I want to have the user input the amount of players and then when the button is pressed it submits the amount and moves to the next screen. But when I test it, the app just crashes and I get the error, "Unhandled event loop exception". here's my code:
package com.example.trivia;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
public static int players;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//locates widgets
Button submit = (Button) findViewById(R.id.submitPlayers);
final EditText howMany = (EditText) findViewById(R.id.editText1);
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//gets number of players from text field then goes to next activity
players = Integer.parseInt(howMany.getText().toString());
Intent intent = new Intent(v.getContext(), PlayerMenu.class);
startActivityForResult(intent, 0);
}
});
}
@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;
}
}
0 comments:
Post a Comment