I just started learning Computer Science and Android development. I've been going through some helloworld demos to try and learn.
So going wild, I tried to rewrite a program that has one button for two buttons using the onClickListener. While I don't have any compiling errors, my program is force closing on me:
01-05 11:20:33.968: E/AndroidRuntime(3257): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multbuttontest/com.example.multbuttontest.MultiButtonActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class button
My XML file looks like so (Sorry I suck at formatting):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MultiButtonActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and code:
package com.example.multbuttontest;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
public class MultiButtonActivity extends Activity implements View.OnClickListener{
Button button1, button2;
int touchCount1, touchCount2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multi_button);
button1 = (Button) findViewById(R.id.button1);
button1.setText( "Touch Button 1!");
button1.setOnClickListener(this);
button2 = (Button) findViewById(R.id.button2);
button2.setText( "Touch Button 2!");
button2.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.button1:
touchCount1++;
button1.setText("Touched b1 " + touchCount1 + " times(s)");
break;
case R.id.button2:
touchCount2++;
button2.setText("Touched b2 " + touchCount2 + " times(s)");
break;
}
}
}
This is strictly just for my learning purposes, and the code does suck. Any help would be appreciated.
It's not button, it's Button. The XML tag points to the java class in the framework. And Java is case sensitive.
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Here is some code that might help you out.
MainActivity:
public class MainActivity extends Activity
{
private TextView txt1;
private Button btnCount,btnClear;
private int num1 = 1;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt1 = (TextView) findViewById(R.id.txt1);
btnCount = (Button) findViewById(R.id.button1);
btnClear = (Button) findViewById(R.id.button2);
}
public void sendMessage(View view)
{
txt1.setText("You have clicked"+ (num1) + "times");
num1++;
}
public void clear(View view)
{
num1 = 1;
txt1.setText("You have clicked"+ (num1) + "times");
}
}
activity_main.xml:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_clear"
android:onClick="clear" />
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+string/pushed" />
Output:
Related
My program opens with a login page, then moves to a page with two buttons (go to counter and go to scan barcode).
Very basic at this point, but I'm stuck because I press the scan barcode button and it moves to the new page fine, but if I press the 'go to counter' button (which goes to a chronometer class), the program crashes - even though there is a class made for it.
It gives me this error:
Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference.
Here is my code
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class page1 extends AppCompatActivity implements View.OnClickListener {
Button scanner,go2count;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page1);
scanner = (Button) findViewById(R.id.scanner);
go2count = (Button) findViewById(R.id.go2count);
scanner.setOnClickListener(this);
go2count.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.scanner:
startActivity(new Intent(this, ScanPage.class));
break;
case R.id.go2count:
startActivity(new Intent(this, ChronoPage.class));
break;
}
}
So if I press the 'scanner' button, it works fine. But if I press the 'go2count' button, the program gives me the error mentioned.
This is the chronometer code:
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Chronometer;
import android.widget.Button;
public class ChronoPage extends AppCompatActivity implements View.OnClickListener {
private Button start;
private Button stop;
private Button resume;
private Button reset;
private long time = 0;
private Chronometer myChrono;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uI();
}
public void uI(){
start = (Button) findViewById(R.id.bStart);
start.setOnClickListener(this);
stop = (Button) findViewById(R.id.bStop);
stop.setOnClickListener(this);
resume = (Button) findViewById((R.id.bResume));
resume.setOnClickListener(this);
reset = (Button) findViewById(R.id.bReset);
reset.setOnClickListener(this);
myChrono = (Chronometer) findViewById(R.id.chronometer);
}
#Override
public void onClick(View v){
if (v == start){
myChrono.setBase(SystemClock.elapsedRealtime());
myChrono.start();
}
else if (v == stop){
time = SystemClock.elapsedRealtime();
myChrono.stop();
// printing();
}
else if (v == resume){
myChrono.setBase(myChrono.getBase() + SystemClock.elapsedRealtime() - time);
myChrono.start();
}
else if (v == reset){
myChrono.setBase(SystemClock.elapsedRealtime());
}
}
}
Another post said to try unchecking the "Use Host GPU" in the AVD manager, but that didn't solve the problem either.
Other posts have the same error, but are more specific to their code. All help is appreciated!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_width="match_parent">
<ImageView
android:id="#+id/logo1"
android:layout_marginTop="100dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/swordlogocopy"/>
<Button
android:id="#+id/scanner"
android:text="Scan Barcode"
android:textColor="#DDC004"
android:background="#000000"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/go2count"
android:text="Go to counter"
android:textColor="#DDC004"
android:background="#000000"
android:layout_width="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_height="wrap_content" />
And the XML layout of the Chrono Page:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_width="match_parent">
<ImageView
android:id="#+id/logo1"
android:layout_marginTop="100dp"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/swordlogocopy"/>
<Chronometer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#000000"
android:id="#+id/chronometer1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:layout_gravity="center_horizontal"
android:id="#+id/bStart"
android:textColor="#DDC004"
android:background="#000000"
android:layout_marginTop="50dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/stop"
android:layout_gravity="center_horizontal"
android:textColor="#DDC004"
android:background="#000000"
android:layout_marginTop="5dp"
android:id="#+id/bStop" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/resume"
android:layout_gravity="center_horizontal"
android:textColor="#DDC004"
android:background="#000000"
android:layout_marginTop="5dp"
android:id="#+id/bResume" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/reset"
android:layout_gravity="center_horizontal"
android:textColor="#DDC004"
android:background="#000000"
android:layout_marginTop="5dp"
android:id="#+id/bReset" />
If you get this error, then most likely the findViewById(id) is not finding your Button variable in your xml to set the corresponding Button and therefore returning null. Which results in a NullpointerException when trying to set a OnClickListener on this view
Check if all Button Ids are valid
I have 3 buttons in my application,
buttons id's = button1, button2, button3.
button1 and button3 need to do the same action, exit the game - working.
button2 need to add 1 to a counter and change a text to the counter (using for a score)
so i made an int counter=0, tried to make the script and the app crashes when I press on button2, here's the logcat and the script:
package com.example.bluetap;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.PaintDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class FirstActivity extends Activity implements OnClickListener {
private TextView changingTextView;
private Button button1;
private Button button2;
private Button button3;
private int counter=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
changingTextView = (TextView) findViewById(R.id.changingTextView);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(this);
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(this);
button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(this);
}
public void onClick(View v) {
int id = v.getId();
if (id == R.id.button1) {
finish();
System.exit(0);
}
else if (id == R.id.button2) {
counter++;
changingTextView.setText(counter);
}
else if (id == R.id.button3) {
finish();
System.exit(0);
}
}
}
here's the main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.bluetap.FirstActivity$PlaceholderFragment" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:minWidth="200dp"
android:text="Press The White Button"
android:textColor="#color/blue" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/button1"
android:background="#android:color/white"
android:minWidth="200dp"
android:text="Press The White Button"
android:textColor="#color/blue" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
android:minWidth="200dp"
android:text="Press The White Button"
android:textColor="#color/blue" />
<TextView
android:id="#+id/changingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_below="#+id/button3"
android:layout_marginLeft="80dp"
android:layout_marginTop="95dp"
android:text="0"
android:textSize="60sp" />
here's the logcat:
TextView.setText(int) expects a resource identifier. You're trying to show the actual int value in your TextView. Android looks for a resource with that value, which it cannot find. Thus crashing your application.
Use changingTextView.setText(String.valueOf(counter)); to convert it to a String first.
you have problem on:
else if (id == R.id.button2) {
counter++;
changingTextView.setText(counter);
}
you can't set integer value to TextView, so you need cast that to String.
you can use:
changingTextView.setText(""+counter);
or
changingTextView.setText(Integer.toString(counter));
or
changingTextView.setText(String.valueOf(counter));
When I click on the add button without entring anything on the edittext,unfortunately calculator has stopped.
package com.example.calculator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Calci extends Activity {
TextView t1;
EditText e1,e2;
Button add,sub,mul,div;
Context c;;
String b,a;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calci);
e1=(EditText) findViewById(R.id.EditText01);
e2=(EditText) findViewById(R.id.EditText02);
add=(Button) findViewById(R.id.add);
sub=(Button) findViewById(R.id.sub);
mul=(Button) findViewById(R.id.mul);
div=(Button) findViewById(R.id.div);
t1=(TextView) findViewById(R.id.textView1);
a=e1.getText().toString();
b=e2.getText().toString();
}
public void doSomething(View v){
if(v.getId()==R.id.add){
if (a==null & b==null){
Toast.makeText(c,"PLEASE ENTER SOMETHING", Toast.LENGTH_LONG).show();
}
else{
int result=Integer.parseInt(a) + Integer.parseInt(b);
t1.setText(Integer.toString(result));
}
}
}
}
When I click on the add button,unfortunately calculator has stopped.
XML FILE
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Calci" >
<EditText
android:id="#+id/EditText01"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/EditText02"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/EditText01"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/EditText01"
android:layout_marginTop="20dp"
android:text="ADD"
android:onClick="doSomething"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button4"
android:layout_marginTop="44dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/add"
android:onClick="doSomething"
android:text="SUBTRACT" />
<Button
android:id="#+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/sub"
android:onClick="doSomething"
android:text="MULTIPLY" />
<Button
android:id="#+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/mul"
android:onClick="doSomething"
android:text="DIVIDE" />
</RelativeLayout>
When I click on the add button,unfortunately calculator has stopped.\
what shuold i do now
First of all initialize
t1=(TextView) findViewById(R.id.textView1);
And you can put validation for empty check on button click listener before furthe process like
if(!(t1.getText.toString().equals(""))) to show alerts
I think problem is that you have not declared your text-view, try to declare it like below and then try.
t1=(TextView) findViewById(R.id.textView1);
Edit
if (e1.getText.toString().trim() == "" && e2.getText.toString().trim() == "")
{
// alert
}
else
{
// do your code
}
So your final code would be
public void doSomething(View v){
if(v.getId()==R.id.add){
a=e1.getText().toString();
b=e2.getText().toString();
if (a == "" && b == "")
{
// alert
}
else
{
int result=Integer.parseInt(a) + Integer.parseInt(b);
t1.setText(Integer.toString(result));
}
}
}
At first you have mistake in your function - you should call e1.setText(), not t1, t1 undeclared and not initialized. And next you should use OnClickListener like this:
public class Calci extends Activity {
TextView t1;
EditText e1,e2;
Button add,sub,mul,div;
String b,a;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calci);
e1=(EditText) findViewById(R.id.EditText01);
e2=(EditText) findViewById(R.id.EditText02);
add=(Button) findViewById(R.id.add);
sub=(Button) findViewById(R.id.sub);
mul=(Button) findViewById(R.id.mul);
div=(Button) findViewById(R.id.div);
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a=e1.getText().toString();
b=e2.getText().toString();
int result=Integer.parseInt(a) + Integer.parseInt(b);
e1.setText(Integer.toString(result));
}
});
}
}
And yes, check the textfield for not empty String.
if((!a.isEmpty())&(!b.isEmpty())) { your code }
And the best way - use try-catch for catching FormatNumberException
try {
int result=Integer.parseInt(a) + Integer.parseInt(b);
e1.setText(Integer.toString(result));
}
catch (FormatNumberException e) {
Log.d("Exception", e.getMessage());
}
So you can prevent all crashes.
I have created following Custom Preference Screen.
I want to add Listener on Button1 and Button2. How should I do it?
I am using following code for creating above Preference Screen.
DemoPref:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class DemoPref extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startActivity(new Intent(this, MyPref.class));
}
}
MyPref:
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyPref extends PreferenceActivity{
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//setContentView(R.layout.tftp_setting);
this.addPreferencesFromResource(R.xml.list_pref);
/*Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.i("MyPref", "Button1 one is clicked.");
}
});
Button b2 = (Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.i("MyPref", "Button2 one is clicked.");
}
});*/
}
}
res\layout\setting.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="fill_parent"
android:orientation="vertical"
>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="TextView1" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="EditText2" android:id="#+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="TextView2" android:id="#+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="EditText2" android:id="#+id/editText2" android:layout_height="wrap_content" android:layout_width="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:text="Button1" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Button2" android:id="#+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>
res\xml\pref.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen android:title="My Setting" android:layout="#layout/setting" android:summary="This is my setting."></PreferenceScreen>
</PreferenceScreen>
You need:
Button b1 = (Button) findViewById(R.id.button1);
Button b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("MyPref", "Button1 one is clicked.");
}
});
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("MyPref", "Button2 one is clicked.");
}
});
I don't have an answer but have some insight -
The view in which you are trying to find the buttons is NOT settings.xml (or pref.xml) - that's why findViewById returns null.
I think the view (layout) which is loaded is internal Android OS view, with ID 17367111 (or 0x1090047).
The only preference you have in the PreferenceScreen you open is another PreferenceScreen (which uses the settings.xml as layout)
you need to get access to the view of this internal PreferenceScreen and them you'd be able to do:
prefScreeView.findViewByID(R.id.button1);
Hope it helps someone to find the answer.
Button btn = (Button) getPreferenceScreen().findPreference(key);
Developing my first app for android. Works OK on emulator, but on phone I get a "Source not found error" ViewRoot.handleMessage(Message)line:1757. I get the error when I press button number 4 on the application and try to display my media images on phone.
Code:
package com.example.famiily_connect_v1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class family_connect extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button incrementButton, decrementButton, makecallButton,
media_cameraButton;
TextView numberdisplayTextView;
EditText inputEditText;
int A = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
incrementButton = (Button) findViewById(R.id.Button01);
decrementButton = (Button) findViewById(R.id.Button02);
makecallButton = (Button) findViewById(R.id.Button03);
media_cameraButton = (Button) findViewById(R.id.Button04);
numberdisplayTextView = (TextView) findViewById(R.id.TextView01);
inputEditText = (EditText) findViewById(R.id.EditText01);
incrementButton.setOnClickListener(this);
decrementButton.setOnClickListener(this);
makecallButton.setOnClickListener(this);
media_cameraButton.setOnClickListener(this);
numberdisplayTextView.setOnClickListener(this);
inputEditText.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.Button01:
A++;
numberdisplayTextView.setText(String.valueOf(A));
break;
case R.id.Button02:
A--;
numberdisplayTextView.setText(String.valueOf(A));
break;
case R.id.Button03:
break;
case R.id.Button04:
Intent myIntent = new Intent();
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivity(myIntent);
break;
default:
break;
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#00AAAA">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/hello" />
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
<Button android:id="#+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="increment"></Button>
<Button android:id="#+id/Button02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="decrement"></Button>
<Button android:id="#+id/Button03" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="make call"></Button>
<Button android:id="#+id/Button04" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="media_camera"></Button>
<TextView android:id="#+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="24sp"
android:text="0" android:textStyle="bold" android:textColor="#000000"></TextView>
<EditText android:id="#+id/EditText01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="enter new button text"></EditText>
<RadioButton android:id="#+id/RadioButton01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="camera"></RadioButton>
</LinearLayout>
Enable in your Eclipse the LogCat
Window > Show View > Other > Android >
LogCat
then you can find what is the real description of your Exception.