I already have tried Cleaning the project and rebuilding it also syncing project with grade files and invalidate caches / restart.
But still I am facing this error.
P.S. I am very new to android programming.
here is my Android Manifest file .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shubhangkhattar.newboston" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.shubhangkhattar.newboston.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.TEXTPLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my MainActivity.java
package com.example.shubhangkhattar.newboston;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends Activity {
int counter;
Button add,sub;
TextView display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add=(Button) findViewById(R.id.bAdd);
sub=(Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counter++;
display.setText("Your Total is " + counter );
}
});
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counter--;
display.setText("Your Total is" + counter);
}
});
}
}
Here is my activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:text="Your Total Is 0"
android:layout_width="fill_parent"
android:layout_height="wrap_ content"
android:textSize="45dp"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/tvDisplay"
/>
<Button
android:id="#+id/bAdd"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Add One"
android:layout_gravity="center"
android:textSize="20dp"
/>
<Button
android:id="#+id/bSub"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Subtract One"
android:layout_gravity="center"
android:textSize="20dp"
/>
</LinearLayout>
This is what my error build gradle shows.
:app:processDebugResources
/Users/shubhangkhattar/AndroidStudioProjects/NewBoston/app/src/main/res/layout/activity_main.xml
Error:(11, 32) String types not allowed (at 'layout_height' with value 'wrap_ content').
/Users/shubhangkhattar/AndroidStudioProjects/NewBoston/app/src/main/res/layout/text.xml
Error:(16) No resource identifier found for attribute 'layout_orientation' in package 'android'
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/shubhangkhattar/Library/Android/sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1
You should import your R file in MainActivity.java
import com.example.shubhangkhattar.newboston.R;
Try to press alt + Enter on highlighted R symbol.
Create another Class "R"
package com.example.asus.yourname;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int b1=0x7f050001;
public static final int text1=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int app_name1=0x7f040003;
public static final int hello=0x7f040000;
public static final int hello1=0x7f040002;
}
}
Related
My AndroidManifest file is showing an error "Unresolved class 'MainActivity' ", but i have a java class and file by that name in the package and it is supposed to be the first activity of the program so when i try to run the program it crashes up , i've checked my code but couldn't find any problem there .
java code for MainActivity file
package com.example.tictactoe;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button forward;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
forward = (Button)findViewById(R.id.start);
forward.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(MainActivity.this,GameUi.class));
}
});
}
#Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setMessage("Do you want to Exit?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton("No",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
}
}
java code for second activity which my program uses ("GameUi.java")
package com.example.tictactoe
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
public class GameUi extends AppCompatActivity {
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_ui);
btn=(Button)findViewById(R.id.backbtn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(GameUi.this, MainActivity.class));
}
});
}
}
AndroidManifest file code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tictactoe">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.TicTacToe">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity xml file code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E5E6AD"
tools:context=".MainActivity">
<TextView
android:id="#+id/Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_marginBottom="332dp"
android:editable="false"
android:text="Hello Aliens!"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="50dp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="#+id/Alienimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/Heading"
app:srcCompat="#drawable/ic_launcher_foreground" />
<Button
android:id="#+id/Startbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000066"
android:letterSpacing="0.5"
android:padding="0dp"
android:text="Start"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Alienimg"
app:layout_constraintVertical_bias="0.886" />
</androidx.constraintlayout.widget.ConstraintLayout>
In your class's I don't see the package at top.
Try adding it and see, if you still face the issue, try invalidate and restarting.
package com.example.tictactoe;
This is the cause of error
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the intent-filter is used to define that which activity will be your first activity ( when you start your Android Application ). You can use it in both activities so the App will confuse which is your first Activity so they give error.
In case MainActivity is your first activity
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
</activity>
Your manifest is Ok ( I guess you fixed the intent-filter issue based on
Abdullah Sheikh answer). the problem is because of this line in MainActivity :
forward = (Button)findViewById(R.id.start);
because your button id is Startbtn not start
just replace that with :
forward = (Button)findViewById(R.id.Startbtn);
also in activity_main and ImageView remove
app:srcCompat="#drawable/ic_launcher_foreground"
or find another src for drawable.
I'm making an Android game in Android Studio.
I first wrote the code for game loop. Then I created a a welcome page/start page and added it to the onclick event.
But when I run the app, and click the "start" button, the app stops abruptly. Here is the Java, XML and manifest files. Did I miss something?
My main activity (Game.java):
public class Game extends ActionBarActivity{
private static Button button_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn off title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game);
onClickButtonListener();
}
public void onClickButtonListener(){
button_sbm=(Button)findViewById(R.id.button);
button_sbm.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent("com.project.androidgame.GAME");
startActivity(intent);
}
}
);
}
/*public void startGame(){
Intent intent=new Intent(Splash.this, Game.class);
startActivity(intent);
}*/
activity_game.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="START"
android:textSize="50sp"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How to play"
android:textSize="24sp"
android:id="#+id/button2"
android:layout_below="#+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
activity for the starting page (Splash.java):
public class Splash extends Activity {
MediaPlayer ourSong;
#Override
protected void onCreate(Bundle ILoveFootball) {
super.onCreate(ILoveFootball);
setContentView(R.layout.splash);
ourSong=MediaPlayer.create(Splash.this,R.raw.splashsound);
ourSong.start();
Thread timer=new Thread(){
public void run()
{
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint=new Intent("com.project.androidgame.GAME");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
ourSong.release();
finish();
}
}
splash.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splash_back">
manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:screenOrientation="landscape"
android:name=".Splash" android:label="AndroidGame">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
<intent-filter>
<action android:name="com.project.androidgame.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Follow this step to edit your code
In your manifest, remove the intent-filter in the second activity, intent-filter is only use to recognize a start up activity. Change this
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
<intent-filter>
<action android:name="com.project.androidgame.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
To this
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
</activity>
The best way to start an activity is the present content to the next class an example
Intent intent=new Intent(Splash.this, Game.class);
startActivity(intent);
I have been messing around with this for a few days now and have the code identical to that in the tutorial and yet it still doesn't want to work, Why?
MainActivity.java
package com.example.mdpmk1;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.scan);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, ScanScreen.class);
startActivity(intent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Screen One......"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/scan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click me to another screen" />
</LinearLayout>
ScanScreen.java
package com.example.mdpmk1;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class ScanScreen extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan_screen);
}
}
scan_screen.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You have done it!!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any help would be lovely, This has relay been annoying me and i know that it is probably a simple mistake.
Add the following in your AndroidManifest.xml
<activity android:name=".ScanScreen" />
within application like so:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScanScreen" />
</application>
Here is a quote from the official docs on what the activity tags are for:
Declares an activity (an Activity subclass) that implements part of
the application's visual user interface. All activities must be
represented by elements in the manifest file. Any that are
not declared there will not be seen by the system and will never be
run.
That last sentence is important.
In your case writing <activity android:name=".ScanScreen" /> above </application> will solve your problem.
Whenever you need to use any activity in android you have to mention it in AndroidManifest.xml file. Just giving answer to you won't help you.
You should first read on below links to understand what is intent and intent-filters used for.
http://developer.android.com/reference/android/content/Intent.html
http://developer.android.com/guide/components/intents-filters.html
What is an Intent in Android?
Your app crashes because your not setting or registered the activity in manifest.You haven't added the ScanScreen Activity in your manifest file.
Just add the following to your AndroidManifest.xml :
<activity android:name=".ScanScreen" />
within your application tag like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScanScreen" />
</application>
I'm trying to have a user fill out my EditText with a price... i.e. "20.00" and get the value from that edit text as a string. Then use that string as data to be uploaded as a value to "my server" a.k.a parse.com under the "Price" key. Whenever I run my emulator, fill out "20.00" in the edit text, and check my server a new entry never pops up. My logcat returns:
03-23 21:14:20.607: V/EditText(1697): 20.00
If I create another string above and simply give it a value. Then put it under the "Price" key instead of myString and run the emulator, my server will receive this and everything will workout.
Since the value set under the key "Price" is a string and my logcat is returning an EditText whenever I use myString, this is leading me to believe that I am using an EditText instead of a String even though I have looked up multiple tutorials/ answers that all say in order to get the string from an edit text you have to use:
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
which I have in my code.
Also, I have two SearchViews and two ListViews above that have search functionality so my code is a little lengthy. My code does not error out at all and it works fine besides for this minor hiccup.
TapDeal.java - problem class:
package com.alpha.dealtap;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.parse.Parse;
import com.parse.ParseObject;
public class TapDeal extends Activity {
Button b1;
String newString;
// List view
private ListView lv;
private ListView lv2;
// Listview Adapter
ArrayAdapter<String> adapter;
ArrayAdapter<String> adapter2;
// Search EditText
EditText inputSearch;
EditText inputSearch2;
EditText price;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
ArrayList<HashMap<String, String>> productList2;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tapdeal);
// Listview Data
String products[] = { "Dubra", "Keystone Light", "Keystone",
"Smirnoff", "Jack Daniels", "Captain Morgan", "Grey Goose",
"Burnetts", "Kettle One", "Corona", "Franzia", "Budweiser" };
String size[] = { "6 Pack", "12 Pack", "30 Pack", "750ml", "Handle",
"1 liter", "3 Liter Box", "Half Pint", "1 Pint" };
lv = (ListView) findViewById(R.id.list_view);
lv2 = (ListView) findViewById(R.id.list_view2);
inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch2 = (EditText) findViewById(R.id.inputSearch2);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.listitem,
R.id.product_name, products);
adapter2 = new ArrayAdapter<String>(this, R.layout.size, R.id.size,
size);
lv.setAdapter(adapter);
lv2.setAdapter(adapter2);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// When user changed the Text
TapDeal.this.adapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
inputSearch2.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
TapDeal.this.adapter2.getFilter().filter(s);
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
b1 = (Button) findViewById(R.id.button1);
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
Parse.initialize(this, "xxxx", "yyyy");
ParseObject dealinfo = new ParseObject("Deals");
dealinfo.put("Brand", "Budweiser");
dealinfo.put("Size", "6");
dealinfo.put("Price", newString);
dealinfo.saveInBackground();
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("EditText", price.getText().toString());
}
});
}
}
("xxxx" and "yyyy" are my private keys).
tapdeal.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Editext for Search -->
<EditText
android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Brand of Alcohol"
android:inputType="textVisiblePassword" />
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="52dp" />
<EditText
android:id="#+id/inputSearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Enter the Size"
android:inputType="textVisiblePassword" />
<ListView
android:id="#+id/list_view2"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:layout_weight="0.16" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="Enter the Price"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="Tap it"
android:textSize="23dp" />
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alpha.dealtap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Search_Page"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.SEARCH_PAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".DealPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.DEALPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".StorePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.STOREPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Map"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TapDeal"
android:label="TapDeal"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="com.alpha.dealtap.TAPDEAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for your help!
It's not entirely clear from your question what is happening and what you expect to happen, but it seems odd that the onClick() method of your listener only outputs to the log. My guess is that you want all of this code:
String newString = price.getText().toString();
ParseObject dealinfo = new ParseObject("Deals");
dealinfo.put("Brand", "Budweiser");
dealinfo.put("Size", "6");
dealinfo.put("Price", newString);
dealinfo.saveInBackground();
in your onClick() method so that it happens when the button is clicked, instead of in the onCreate() method as it is now. If that's not what you're trying to achieve, then you'll have to edit your question to make it a lot clearer.
SOLVED: Put my file in the wrong folder, my stupid mistake :)
Anyone knows why this won't work? It just doesn't do anything. I have everything in the Main XML defined properly i think, but i feel like something is missing here.
I am new to Java/Android developing but i was using VB.NET for a long time.
package com.example.myfirstapplication;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.os.Bundle;
import android.app.Activity;
public class Main extends Activity{
int counter;
Button add, sub;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAddOne);
sub = (Button) findViewById(R.id.bSubOne);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your total is " + counter);
}
});
}
}
Thanks in advance.
EDIT: Added layout. Thought it wasn't needed:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:layout_gravity="center"
android:textSize="45dp"
android:id="#+id/tvDisplay"/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Add 1"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/bAddOne" />
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Subtract 1"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/bSubOne"/>
</LinearLayout>
Edit: And the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapplication"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Ok. A quick fix is to change the name of the Activity from Main.java to MainActivity.java.
package com.example.myfirstapplication;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity{
int counter;
Button add, sub;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAddOne);
sub = (Button) findViewById(R.id.bSubOne);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your total is " + counter);
}
});
}
}
The reason is That in the AndroidManifest.xml the starting Activity is declared as MainActivity:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It is in the line that says: android:name=".MainActivity", and the
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
says that it is the starting and main activity.