0

So I'm trying to make the button redirect to another class, my application is stopping when I try to click the button Play and this is what the logcat says

Caused by: java.lang.NullPointerException at com.example.kenneth.rusa.Play.onCreate(Play.java:26)

Play, java:26 is

Button play = (Button) findViewById(R.id.playb);
play.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent(Play.this, GamePanelEasy.class));
}

Here's my manifest:

<activity android:screenOrientation="landscape" android:name=".Play">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

I don't have any errors but it's still crashing, I don't know why the logcat says I have error in line 26 which is play.setOnClickListener(new View.OnClickListener(){ }

Thanks for the help guys I found out what's my problem playb was been duplicated from another class I changed it to easyb so it works fine now thanks!

2 Answers2

0

If your app crashes in between lines you posted there is only one possibility. You are trying to invoke setOnClickListener() method to a null reference here:

play.setOnClickListener(new View.OnClickListener() {

Check if R.id.playb id is in layout you inflate in onCreate().

Mr Quattro
  • 331
  • 1
  • 5
0
<activity android:name="GamePanelEasy"
   android:label="@string/app_name">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />
   </intent-filter>
</activity>

--have you declare your second activity in the manifest?

Francesco Taioli
  • 2,687
  • 1
  • 19
  • 34