I am new to Android programming, and I am making a number guessing game to get to know the basic Android code. In my program, I have an EditText (basically a TextField) and I was wondering how I would change whatever the user inputs into an int. So far I have tried Integer.parseInt(string), but it didn't work. Here is the code that I have right now:
EditText textfield = (EditText) findViewById(R.id.textfield);
String label = textfield.getText().toString();
int guess = Integer.parseInt(label);
When I run this program to debug on my phone, it all works fine until I press the button that I call this code with. When I press the button, the program closes and a popup comes that says
"The application Test (process com.android.test) has stopped unexpectedly. Please try again."
This happens every time I try to run the program. I have debugged, and I have isolated the problem to the line of code that parses the int. How do I make this work?
try...catcharound it and analyze the exception?