Error code with AHPreferenceManager

William Hunter

Active Member
Licensed User
Longtime User
I am using AHPreferenceManager of the AHPreferenceActivity Library. I use the code below to set the value of a variable Dim’d in Process_Globals as an integer.

I would like to take a specific action if a null string is found. The problem I have is when a null string is found I get a java.lang.NumberFormatException. The rest of the code works fine.

The code seems right to me, yet it doesn’t work. Is there a way do this without the error? Any help greatly appreciated.

Regards :)
B4X:
If Manager.GetString("edit5") < 0 OR Manager.GetString("edit5") = "" Then ' null string gives java.lang.NumberFormatException
   sDelay1 = 1
   Log("sDelay1 = " & sDelay1) ' debug
Else
   sDelay1 = Manager.GetString("edit5")
   Log("sDelay1 = " & sDelay1) ' debug
End If

B4X:
java.lang.NumberFormatException: 
   at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
   at java.lang.Double.parseDouble(Double.java:287)
   at mail.purge.main._vvvvvvvvvvvvvvvvvvvvvv4(main.java:4118)
   at mail.purge.main._activity_resume(main.java:710)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at mail.purge.main$ResumeMessage.run(main.java:192)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NumberFormatException:

Edit - This issue has been resolved by reversing the request order in the If statement.
B4X:
If Manager.GetString("edit5") = "" OR Manager.GetString("edit5") < 0 Then
   sDelay1 = 1
   Log("sDelay1 = " & sDelay1) ' debug
Else
   sDelay1 = Manager.GetString("edit5")
   Log("sDelay1 = " & sDelay1) ' debug
End If
 
Last edited:
Top