-2
public class MainActivity extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_screen);
        ImageButton x = (ImageButton) findViewById(R.id.imageButton1);
        x.setOnClickListener(this);
    }

    public void onClick(View v) {
        Intent intent = new Intent(
                com.example.choiceisaseriousmatter.MainActivity.this,
                Choice.class);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is
        // present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

This code is for switching to another Activity when the imageButton is clicked. But whenever I click on the button the program just crashes.

Binoy Babu
  • 16,699
  • 17
  • 91
  • 134

2 Answers2

1

Are you already override the onClick method? Try this change:

@Override
public void onClick(View v) {
    Intent intent = new Intent(MainActivity.this, Choice.class);
    startActivity(intent);
}
heri.wijoyo
  • 276
  • 1
  • 6
0

You must add Choice Activity to the AndroidManifest.xml.

<activity android:name=".Choice" />

This question is very similar.

Community
  • 1
  • 1
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134