0

An app published on market has an error:

java.lang.NumberFormatException

below the stack.

Is the cause this code?

fade = Integer.parseInt(ListPreference);

I see "OTHER" devices has affected by this crash. Any idea?

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Notify}: java.lang.NumberFormatException: unable to parse '' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3768)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: unable to parse '' as integer
at java.lang.Integer.parseInt(Integer.java:362)
at java.lang.Integer.parseInt(Integer.java:332)
at com.example.app.Notify.onCreate(Notify.java:33)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more

3 Answers 3

1

java.lang.NumberFormatException: unable to parse '' as integer at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)

==> it seems you are trying to parse an empty string. You should include the parsing operation in a try/catch block and deal with malformed inputs.

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

5 Comments

in your stacktrace: com.example.app.Notify.onCreate(Notify.java:33) => line 33 of the Notify.java file. Which probably is the one you quoted.
thanks. This values is read from sharedpreferences. Can I check with an IF? if (value.isEqual(null)) { [...] } else { value = "value" } How I check if a string value is empty? thanks!
If ListPreference were null, you would get a NullPointerException. You can check for empty with if(ListPreference.isEmpty(), but I would simply use a try/catch block which will handle any malformed input, not just empty strings => more bullet proof.
Ok thanks. This value set a "fade on activities" so, at first time fade should be 1500. I think there's another bug. For now, can I resolve checking if value isEmpty() and if yes set to 1500 with try/catch or is better if if/else? thanks!
I would use: try { fade = Integer.parseInt(ListPreference); } catch (Exception e) { /*log if you want*/ fade = 1500; }
1

as in log :

NumberFormatException: unable to parse '' as integer

you are trying to parse space to integer . before parsing string value to Integer check for null or empty

Comments

1

Actually, There is any symbol or character happen in String ListPreference,

Its better to Handle this exception.

try {
     fade = Integer.parseInt(ListPreference);
} catch (NumberFormatException e) {
        Log.e("Exception",e.toString());
}

Update:

Look at the Jakarta Commons :

NumberUtils.isNumber()

This can be used to check most whether a given String is a number.

Also before using String ListPreference just removed white space from it using trim().

Using ListPreference.trim() and also check the length of ListPreference whether length is greater than 1 or not.

like, ListPreference.length() > 1

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.