2

I am getting the following crash...

04-27 03:19:08.858: E/AndroidRuntime(448): java.lang.RuntimeException: Unable to start activity ComponentInfo{walmart.namespace/walmart.namespace.WalmartActivity}: java.lang.NumberFormatException: unable to parse '' as integer.

I have no idea what the problem here is, especially because i don't even have a " in my code.

Here is my code...

2
  • 3
    In the future, please post the appropriate code here in the question, rather than on an external link. Commented Apr 29, 2012 at 3:21
  • If your question has been answered, or if it is no longer valid, please 'tick' to choose the most appropriate answer so everyone knows that the problem has been resolved. Thanks. Commented May 14, 2012 at 13:42

3 Answers 3

1

You should do input validation on your fields. Based on the error message, it looks like you're trying to parse an empty string. Instead, you should check whether the string is empty, then try to parse the int.

As Chin Boon pointed out, you should use Integer.parseInt(String).

To prevent your program from crashing outright, you can also wrap the line in a try/catch block, catching the NumberFormatException and handling it appropriately.

Sign up to request clarification or add additional context in comments.

1 Comment

Good; you stated what the problem actually is. (" is not '')
0

Trim and chomp the value before you parse the string into the Integer.

Suspect that there could be spaces or new line character.

Best to use parseInt method of Integer class for this purpose although new Integer(mystery) implicitly uses parseInt.

int a = Integer.parseInt(myStr);

1 Comment

Assuming i put it in my public view and renaming mystring to department, i'm now getting an error of The method parseInt(String) in the type Integer is not applicable for the arguments (EditText).
0

Its probably on this line...

switch (new Integer(department.getText().toString()).intValue()) {

I will suggest that there is a character somewhere in the department that has been passed in but doesn't get printed out to the error output, such as new line characters, tabs, or other white space characters that are unprintable?

Not sure if maybe there are characters in there due to how it is being input to the field, or maybe something due to unicode or the keyboard inputting unusual values?

Could you check this, and post some code here if its still not working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.