Android: converting String to int Android: converting String to int android android

Android: converting String to int


Change

try {    myNum = Integer.parseInt(myString.getText().toString());} catch(NumberFormatException nfe) {

to

try {    myNum = Integer.parseInt(myString);} catch(NumberFormatException nfe) {


It's already a string? Remove the getText() call.

int myNum = 0;try {    myNum = Integer.parseInt(myString);} catch(NumberFormatException nfe) {  // Handle parse error.}


You just need to write the line of code to convert your string to int.

 int convertedVal = Integer.parseInt(YOUR STR);