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

PowerSourceActivity: App crashes on entering an invalid value #2484

Closed
AsCress opened this issue Jun 15, 2024 · 2 comments · Fixed by #2485
Closed

PowerSourceActivity: App crashes on entering an invalid value #2484

AsCress opened this issue Jun 15, 2024 · 2 comments · Fixed by #2485
Assignees

Comments

@AsCress
Copy link
Contributor

AsCress commented Jun 15, 2024

Actual Behaviour
In the PowerSourceActivity, whenever an invalid (non-float parsable) value is entered as an input, the app crashes.

Expected Behaviour
The app should identify whenever the user has input an invalid value, and reset the value to default.

Steps to reproduce it

  1. Open the PowerSourceActivity.
  2. Enter a non-float parsable value (such as "-.", "-V", etc.) as an input in any one of the EditTexts.
  3. One would observe that the app crashes.

LogCat for the issue
FATAL EXCEPTION: main (Ask Gemini)
Process: io.pslab, PID: 19872
java.lang.NumberFormatException: For input string: "-"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at io.pslab.activity.PowerSourceActivity$5.onEditorAction(PowerSourceActivity.java:193)
at android.widget.TextView.onEditorAction(TextView.java:7042)
at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
at android.view.inputmethod.InputConnectionWrapper.performEditorAction(InputConnectionWrapper.java:205)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:357)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:89)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7617)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)

Screenshots of the issue
Here is a recording demonstrating the issue -

Screen_recording_20240615_122759.mp4

Would you like to work on the issue?
Yes

@AsCress AsCress self-assigned this Jun 15, 2024
@marcnause
Copy link
Contributor

Just some information which may be helpful or maybe not (feel free to ignore 😉):

I started working on a horizontal layout for the Power Source a few days ago (see https://github.com/marcnause/pslab-android/tree/powersrc_horizontal). The layout is still unfinished, because I am not good at creating layouts, but I stumbled over exceptions since I use a different locale (German) where decimal points are written as commas ("2.5" is "2,5" for the German locale).

I tried to solve the issue by removing some characters ("+" and the unit) and by using Java's NumberFormat to parse the number (see: 74d58f6).

Since locales don't seem to be handled uniformly in the app (see #2481), I thought that it may be useful to subclass TextViews and EditTexts and use it everywhere in the app.

@AsCress
Copy link
Contributor Author

AsCress commented Jun 15, 2024

@marcnause Thank you so much for that information and updating on your progress on the PowerSource screen. Certainly, a horizontal layout for the screen would be amazing. My main point in this issue is that there are no checks written in the code, which check whether the input is float-parsable or not (like I have done for the Position Controls feature). Even if we subclass the TextViews and EditTexts, we would anyways be needing those checks as the user could still enter non-float parsable values (like '-.' for instance). That's what I wish to work on in the scope of this issue. Does this sound right to you ?

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

Successfully merging a pull request may close this issue.

2 participants