I am getting a force close when there is Int on my edittext and an OK button is pressed.
05-07 16:00:12.945: E/AndroidRuntime(28366): java.lang.NumberFormatException: unable to parse ” as integer
Thats the logcat error I am getting.
Here is the code:
//Button OK
Button bOK = (Button) findViewById(R.id.bOK);
bOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast invalid = Toast.makeText(getApplicationContext(), "Only values between 0-255 will be accepted.", Toast.LENGTH_LONG);
uin = Integer.parseInt(value.getText().toString());
if ( uin <= 255 ) {
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DataOutputStream os = new DataOutputStream(process.getOutputStream());
try {
os.writeBytes("chmod 644 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("echo " +uin+ " > sys/class/leds/button-backlight/brightness\n");
os.writeBytes("chmod 444 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if ( uin > 255 ) {
invalid.show();
}
}
});
How can i tell the app if there is no value input on the EditText ( uin missing ) show toast, and not force close? 😀
Please be gentle on me, this is my second week with java and android, I have never had any programming language experiences before 🙂
You need to surround the line uin = Integer.parseInt(value.getText().toString());
with a try/catch block like this