Force Close Error On Setonclicklistener (example From Hello Android Book Section 3.5)
Solution 1:
Well, you didn't post your logcat output, but since this is such a common beginner's mistake, I'm going to take a wild guess and say that you are probably getting a NullPointerException
.
Your call to findViewById
is probably returning null
, which means that the system could not find the view associated with the id given by R.id.about_content
. I would double check your XML layout for typos.
Solution 2:
Odds are you don't have anything with the id about_content
in main.xml, which will create a NullPointerException.
Also, if aboutButton
is supposed to be a traditional Button, then you should use this:
ButtonaboutButton= (Button) findViewById(R.id.about_content);
Addition
Since aboutButton
is a TextView, use this:
TextViewaboutButton= (TextView) findViewById(R.id.about_content);
but this TextView must be in the layout passed to setContentView() or findViewById() will return null.
Solution 3:
That is because the "main.xml" which you have set your content view ... does not contain the about_content TextView, its in the other xml which you have posted ...
Note: You can access only those R.id's which are present in your setContentView(R.layout.yourlayout) xml ...
Solution 4:
you make setContentView(R.layout.main);
but main.xml
does not include View have id = R.id.about_content
. If you raplace by findViewById(R.id.button1);
It will work.
Solution 5:
This is the solution for
ButtonaboutButton= (Button)findViewById(R.id.about_content);
And dont forget to add testit Activity in Android Manifest
Post a Comment for "Force Close Error On Setonclicklistener (example From Hello Android Book Section 3.5)"