0

I am working on my first Android app for a class. In one activity, one OnClickListener is throwing a Null Pointer Exception. I have identical code for this in another activity which works with no problem. One ImageButton "Main Menu" does not bring you back to the main menu. Here is the relevant Java and the OnClickListener in question is the very last one:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.view.View.OnClickListener;


public class checkYourself extends Activity {
    // Declare our view variables
    private ImageButton mcheck_yourself_button, mtravel_button, mmainMenu;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check_yourself);

        //View object references
        mcheck_yourself_button = (ImageButton) findViewById(R.id.check_yourself_button);
        mtravel_button = (ImageButton) findViewById(R.id.travel_button);
        mmainMenu = (ImageButton) findViewById(R.id.mainmenu);

        //Onclick methods
        mcheck_yourself_button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(checkYourself.this, checkAR.class);
                startActivity(intent);
            }
        });

        mtravel_button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(checkYourself.this, travelMode.class);
                startActivity(intent);
            }
        });

        mmainMenu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(checkYourself.this, MainActivity.class);
                startActivity(intent);
            }
        });

    }
}

Here is the relevant XML for that button

<ImageButton
        android:layout_width="300dip"
        android:layout_height="50dip"
        android:text="Main Menu"
        android:id="@+id/mainMenu"
        android:background="@drawable/mainmenu"
        android:layout_marginBottom="27dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

All Activities are declare in the Android Manifest. Please help!

0 Answers0