I am currently testing my app with a large group of testers and some devices are having really odd issues that don't happen in others.
For some reason one of these issues is the NumberFormatException that just happens when I am converting some Strings to Float (they all come from an ArrayList). In my devices, nothing happens and all the String are converted without a problem. On another person's device however, we get the exception with the following log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fuzzfit/activities.ReportListViewActivity}:
java.lang.NumberFormatException: Invalid float: "0,05"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid float: "0,05"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseFloat(StringToReal.java:310)
at java.lang.Float.parseFloat(Float.java:300)
at activities.ReportListViewActivity.getBiggestItem(ReportListViewActivity.java:141)
at activities.ReportListViewActivity.onCreate(ReportListViewActivity.java:130)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
... 11 more
I am aware that the exception occurs on the "0,05" string, but I have no idea how it even became that in the first place as everything in the first ArrayList was at some point a float before being converted into String. It seems almost as if on his phone the dot in the float number turns into a comma for some reason, and whenever I try to convert it back to float, it causes the NumberFormatException. What can I do to solve this issue? (mind you, it is only happening on some devices!)
Thanks!
That seems likely to be related to running in a different Locale (such as Germany) where the decimal separator character is ','.
If you are actually parsing user input, you need to use a NumberFormat to parse the data.