1

I am making a game in android. I want to make a main menu screen that has two buttons, one to start the game and one to display the how to screen.

I have classes for both, but when I launch my name and test the buttons, the application crashes. Could someone please tell me what is wrong with my code?

       public void launch()
       {
            Intent i = new Intent();
            i.setClassName("com.testing.blockinvasion", "com.testing.blockinvasion.game");
            startActivity(i);
       }

       public void howto()
       {
            Intent i = new Intent();
            i.setClassName("com.testing.blockinvasion", "com.testing.blockinvasion.howto");
            startActivity(i);
       }

}

My buttons are defined in my main.xml:

 <Button
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/Start"
     android:onClick="launch" />

EDIT: I ended up just deleting the project and starting another one and everything seems to work fine now.

Parth
  • 1,226
  • 7
  • 28
  • 49
  • Waqas is correct. If you specify the listener functions using the `android:onClick` attribute then the functions must accept a `View` parameter. – Squonk Feb 04 '12 at 21:14

2 Answers2

2

You need to correct your method signatures. So do it in this way:

public void launch(View v)

and

public void howto(View v)
waqaslam
  • 67,549
  • 16
  • 165
  • 178
0

Try it this way:

private OnClickListener button1Listener = new OnClickListener() { public void onClick(View v) { Intent howto = new Intent(getApplicationContext(), .class); startActivity(howto); } };

Assigning a different OnClickListener object to every button --> button1.setOnClickListener(button1Listener)

Anyway, are all the Activities defined in the AndroidManifest.xml?

Dhanesh Budhrani
  • 190
  • 3
  • 15
  • Initially, I had not defined my activities, but now I have and it still does not load (it prompts me to force close the application) – Parth Feb 04 '12 at 22:36