-3

I change can you help me to see where is wrong because it's the same error log

enter code here
  public class MainActivity extends Activity {
     WebView mWebView;
public ImageButton button01;
public ImageButton button02;
public class MainActivity extends Activity  {

WebView mWebView;
public ImageButton button01;           ``
public ImageButton button02;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(mylayout);
    button01 = (ImageButton) findViewById(R.id.Button01);
    button02 = (ImageButton) findViewById(R.id.Button02);`enter code here`
    button01.setOnClickListener(new ImageButton.OnClickListener(){
    public void onClick(View v){  jumpToLayout03();
   Intent intent = new Intent();
       intent.setClass(MainActivity.this, web.class);
       startActivity(intent); }}


   public void jumpToLayout03() {
       setContentView(activity_main01);
   }

   });}}
enter code here

I change can you help me to see where is wrong because it's the same error log

Eason
  • 469
  • 4
  • 14

2 Answers2

1

It means you have a null pointer on line 37 of your program. In the Main Activity.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
1

You are getting a NullPointerException on line 37 of MainActivity.java. It means that you are trying to access field of an object that is null. So you need to check on line 37 of your program and then see which fields you are accessing on that line of code. Next you need to backtrack those objects to see that they are properly initialized before you use them in line 37.

button02 = (ImageButton)findViewById(R.id.Button02); 
button01 = (ImageButton)findViewById(R.id.Button01); 

button02.setOnClickListener(new Button.OnClickListener() { 
public void onClick(View v) { 
    jumpToLayout03();
     } 

public void jumpToLayout03() { setContentView(activity_main01);}



     button01.setOnClickListener(new Button.OnClickListener() { 
public void onClick(View v) {
 jumpToLayout02();
         } 

public void jumpToLayout02() { setContentView(activity_main)};
azmuhak
  • 964
  • 1
  • 11
  • 31
  • button02 = (ImageButton)findViewById(R.id.Button02); button02.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { jumpToLayout03(); } public void jumpToLayout03() { setContentView(activity_main01); – Eason Apr 01 '15 at 07:37
  • The code you posted in your question is different from what you posted here just now. Is this code working for you ? – azmuhak Apr 01 '15 at 09:30
  • The above code of this response is working for only one button but when I add another button using the same method it doesn't work so I guess if I need to add ( if else) or something like that? – Eason Apr 01 '15 at 10:41
  • it is working for button02 because you are implementing onclicklistener for button02 only. Add a new onclicklistener for button01 as well.. – azmuhak Apr 01 '15 at 12:44
  • check the code i added to my answer.. – azmuhak Apr 01 '15 at 12:50
  • I have tried ,but still the same error – Eason Apr 02 '15 at 01:15
  • Can I mail you my code?because it always appear something like your code grammer wrong – Eason Apr 02 '15 at 01:24