Reputation: 1
I'm working on my first android application a simple yahtzee game. Currently I'm trying to restart my game by clicking a play again button. I've switched views (gameover.xml) and have the onclick in the xml point to a playagain function.
I've kind of got two questions regarding this, first would be that even with an empty method the button causes the application to crash. I'm not exactly sure why. The second is what would be the best method for restarting my game? I was thinking that restarting the activity would be the easiest way but I'm open to other suggestions. Below is the xml code for my play again button:
<Button
android:id="@+id/playbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play Again"
android:layout_weight="1"
android:onClick="playagain"
>
</Button>
I've tried a couple of different methods for restarting my game but haven't been able to test if they work because my app keeps crashing as soon as the button is pressed. In case I've got something setup incorrectly here's the empty playagain function:
private void playagain(){
}
I appreciate the help. This site has provided lots of answers for me throughout the development process.
Upvotes: 0
Views: 515
Reputation: 1006819
playagain()
needs to take a View
as a parameter, and it needs to be a public
method:
public void playagain(View v) {
// something
}
Upvotes: 1