Wraithious Wraithious - 6 months ago 13
Java Question

blank number field causing fatal exception even if checked

I'm trying to make sure when you forget to enter a number that my app won't crash, I have a text field called
edit that only accepts numbers, I am getting this error when i test what happens if you don't enter anything in the text field, which is a numeric text field and only brings up the number keyboard on your device, so you cant enter text at all just numbers
can anyone tell me what I'm doing wrong?

this is the error message:
Process: com..rhgtimecard, PID: 27379
java.lang.NumberFormatException: Invalid int: ""
at com.

And this is the related code block

if (login == 1) {
int getemn = 0;
if (!edit.equals("")) {//**if you didn't enter anything but pressed set anyway this should stop the rest of the code block.
//I tried setting this to if (edit != null) didn't work either, tried setting this to if (!edit.equals()) but it wont
//compile like that at all**
getemn = Integer.parseInt(edit.getText().toString());//**this is line 478 that throws the fatal exception error**
String getemp = edit2.getText().toString();
String allpass = "Passwords";
SharedPreferences loadPass = getSharedPreferences(allpass, MODE_PRIVATE);
String empStrng = String.valueOf(getemn);
String passes = "pass";
if (getemn < 13) {
passes = "pass" + empStrng;
g.setData4(getemn, loadPass.getString(passes, "0123"));
String[] pass = g.getData4();
if (i == 0 && getemp.equals(pass[getemn])) {
if (i == 0 && !(getemp.equals(pass[getemn]))) {
tfone.setText("No matches found");
tftwo.setText("Enter password");
i = 1;

can anyone tell me where I went wrong here or how to actually check if someone entered a number?

Drv Drv

Try this: