java.lang.NumberFormatException: Invalid int: "" in android

Code_Insanity picture Code_Insanity · May 24, 2013 · Viewed 28.1k times · Source

I already know what is causing this error, I just do not know how to handle the case when a user doesn't enter anything into the dialogue box, then hit the button which parses the string into an int. It can't parse an empty string into an int, so it throws an error. I have done some research on how to do this, but have not found a satisfactory result that works.

Problem: How do you check to see if the dialogue box has text in it, before it tries to run the rest of the code.

Answer

codeMagic picture codeMagic · May 24, 2013

Some code would help with the syntax but basically

 if ("".equals(text)  // where text is the text that you get from an EditText or wherever you get it
 {    // give message to enter valid text;    }

Also, you can surround with a try/catch and catch a numberFormatException then print an appropriate message