Converting a string to an integer on Android

See the Integer class and the static parseInt() method: http://developer.android.com/reference/java/lang/Integer.html Integer.parseInt(et.getText().toString()); You will need to catch NumberFormatException though in case of problems whilst parsing, so: int myNum = 0; try { myNum = Integer.parseInt(et.getText().toString()); } catch(NumberFormatException nfe) { System.out.println(“Could not parse ” + nfe); }

Convert an integer to an array of digits

The immediate problem is due to you using <= temp.length() instead of < temp.length(). However, you can achieve this a lot more simply. Even if you use the string approach, you can use: String temp = Integer.toString(guess); int[] newGuess = new int[temp.length()]; for (int i = 0; i < temp.length(); i++) { newGuess[i] = temp.charAt(i) – ‘0’; } … Read more