-5

This is the Java

The logcat says-

Caused by: java.lang.NullPointerException: 
Attempt to invoke virtual method 
'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' 
on a null object reference
Uniruddh
  • 4,427
  • 3
  • 52
  • 86

2 Answers2

0

ok..i got your java file

please update it to this

button = (Button)findViewById(R.id.button);
//remove { from end
Ashwani
  • 1,294
  • 1
  • 11
  • 24
0

In your code I can see that based on some button click you are calling setContentView() again.

Hence I assume you have more buttons is in other layout file. So findViewById function for the button which is in other view will only work after setContentView for that view has been called.

So may be you can put the dependent code inside first OnClick() event where you are changing the content view.

Arpit Ratan
  • 2,976
  • 1
  • 12
  • 20