So I am trying to create a card counting application for blackjack however when I try to set the number of decks that someone is playing with and grab it from the editable editText the program seems to crash. Specifically it says "Unfortunately "My App" has been stopped."
Here is the code of what I have done.
public int numberOfDecks;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activityName)
final EditText numberField = (EditText) findViewById(R.id.editNumber);
Button button = (Button) findViewById(R.id.buttonDecks);
button.setOnClickListener(new OnclickListener() {
public void onClick(View arg0) {
numberOfDecks = Integer.parseInt(numberField.getText().toString());
//Because this didn't work I also tried doing
//numberOfDecks = Integer.getInteger(numberField.getText().toString());
//However both yield the same problem
}
}
}
At first I thought it had to do with a problem with the on click method and parsing the int, or maybe a blank EditText field however, this onClick happens after the editable has been editted with. Next I tried putting it after the code block with the on click and the same result still occurs and before but obviously this stops because the EditText is empty.
EDIT: The EditText box is a number based EditText box, so the only valid input is a number