Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberFormatException when updating distance and can never open the setting page anymore #292

Closed
tingsu opened this issue Mar 1, 2020 · 3 comments
Labels
Milestone

Comments

@tingsu
Copy link

tingsu commented Mar 1, 2020

This exception was found on the master (v1.4.0, the latest code version) and a Google Android phone. This crash issue is similar to #285 but was caused from another function.

STR: Go to setting, click Location Service, choose Network, open Update distance, delete the default value 50 (leave the EditText empty), and click OK.

The exception trace:

 Process: de.rampro.activitydiary.debug, PID: 30606
 java.lang.NumberFormatException: Invalid int: ""
 	at java.lang.Integer.invalidInt(Integer.java:138)
 	at java.lang.Integer.parseInt(Integer.java:358)
 	at java.lang.Integer.parseInt(Integer.java:334)
 	at de.rampro.activitydiary.ui.settings.SettingsActivity.updateLocationDist(SettingsActivity.java:215)
 	at de.rampro.activitydiary.ui.settings.SettingsActivity.onSharedPreferenceChanged(SettingsActivity.java:137)
 	at android.app.SharedPreferencesImpl$EditorImpl.notifyListeners(SharedPreferencesImpl.java:479)
 	at android.app.SharedPreferencesImpl$EditorImpl.apply(SharedPreferencesImpl.java:387)
 	at android.support.v7.preference.Preference.tryCommit(Preference.java:1613)
 	at android.support.v7.preference.Preference.persistString(Preference.java:1644)
 	at android.support.v7.preference.EditTextPreference.setText(EditTextPreference.java:69)
 	at android.support.v7.preference.EditTextPreferenceDialogFragmentCompat.onDialogClosed(EditTextPreferenceDialogFragmentCompat.java:96)
 	at android.support.v7.preference.PreferenceDialogFragmentCompat.onDismiss(PreferenceDialogFragmentCompat.java:270)
 	at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1323)
 	at android.os.Handler.dispatchMessage(Handler.java:102)
 	at android.os.Looper.loop(Looper.java:148)
 	at android.app.ActivityThread.main(ActivityThread.java:5417)
 	at java.lang.reflect.Method.invoke(Native Method)
 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Once this issue happens, the setting page cannot be opened, and the app crashes with the exception trace below.

FATAL EXCEPTION: main
 Process: de.rampro.activitydiary.debug, PID: 30734
 java.lang.RuntimeException: Unable to start activity ComponentInfo{de.rampro.activitydiary.debug/de.rampro.activitydiary.ui.settings.SettingsActivity}: java.lang.NumberFormatException: Invalid int: ""
 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
 	at android.app.ActivityThread.-wrap11(ActivityThread.java)
 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
 	at android.os.Handler.dispatchMessage(Handler.java:102)
 	at android.os.Looper.loop(Looper.java:148)
 	at android.app.ActivityThread.main(ActivityThread.java:5417)
 	at java.lang.reflect.Method.invoke(Native Method)
 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.NumberFormatException: Invalid int: ""
 	at java.lang.Integer.invalidInt(Integer.java:138)
 	at java.lang.Integer.parseInt(Integer.java:358)
 	at java.lang.Integer.parseInt(Integer.java:334)
 	at de.rampro.activitydiary.ui.settings.SettingsActivity.updateLocationDist(SettingsActivity.java:215)
 	at de.rampro.activitydiary.ui.settings.SettingsActivity.onCreate(SettingsActivity.java:479)
 	at android.app.Activity.performCreate(Activity.java:6237)
 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
 	... 9 more
@tingsu
Copy link
Author

tingsu commented Mar 1, 2020

The culprit code is similar to #285 .

int v = Integer.parseInt(value.replaceAll("\\D",""));

You can also use the similar fix as I mentioned in #285 to resolve this crash.

@ramack
Copy link
Owner

ramack commented Apr 20, 2020

yes and it might be worth to search for other places where we use such number (or date) formatting...

@ramack ramack added the bug label Apr 20, 2020
@ramack ramack added this to the v1.5.0 milestone Apr 20, 2020
@ramack ramack closed this as completed in 11f7f39 Apr 18, 2022
@tingsu
Copy link
Author

tingsu commented Apr 19, 2022

Thank you for fixing this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants