Android Question [Solved] Error in PreferencesDialog if 1 is set as switch value

AnandGupta

Expert
Licensed User
Longtime User
I have Sqlite db with text and integer (having 1 or 0 for boolean)
I use PreferencesDialog to input each row.

Now if data row has 0 as integer then the boolean in PreferencesDialog show switch as OFF.
But if data row has 1 as integer then the boolean in PreferencesDialog show error below, instead of showing switch as ON
B4X:
Logger connected to:  Xiaomi M2006C3MII
--------- beginning of system
--------- beginning of main
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 442 (PreferencesDialog)
java.lang.RuntimeException: Cannot parse: 1 as boolean
    at anywheresoftware.b4a.BA.parseBoolean(BA.java:640)
    at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:710)
    at b4a.B4XPages_SQLiteLight2.preferencesdialog._filldata(preferencesdialog.java:2459)
    at b4a.B4XPages_SQLiteLight2.preferencesdialog$ResumableSub_ShowDialog.resume(preferencesdialog.java:587)
    at b4a.B4XPages_SQLiteLight2.preferencesdialog._showdialog(preferencesdialog.java:405)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7184)
    at android.view.View.performClickInternal(View.java:7157)
    at android.view.View.access$3500(View.java:821)
    at android.view.View$PerformClick.run(View.java:27660)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

How to fix it ?
 

Attachments

  • WhatsApp Image 2023-06-11 at 12.40.25 AM.jpeg
    WhatsApp Image 2023-06-11 at 12.40.25 AM.jpeg
    35.9 KB · Views: 61
  • WhatsApp Image 2023-06-11 at 12.35.43 AM.jpeg
    WhatsApp Image 2023-06-11 at 12.35.43 AM.jpeg
    53.7 KB · Views: 62

Daestrum

Expert
Licensed User
Longtime User
Java Booleans are true or false, unlike c they have no numeric value. (in c false = 0 and true = 1)
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
convert numeric value to boolean:
    'showCity is 1 or 0'
    dim blnShowCity as boolean=showCity.As(Boolean)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
'showCity is 1 or 0' dim blnShowCity as boolean=showCity.As(Boolean)
I don't think your code is correct. You can use something like this:
B4X:
Dim showCity As Int =1
    Dim  blnShowCity As Boolean = IIf(showCity = 1, True, False)
    Log(blnShowCity)
 
Upvote 0
Solution

AnandGupta

Expert
Licensed User
Longtime User
Thanks to all.

Somehow I got log =1 for switch ON value in my app. Now trying to create a sample app I found log value as true/false for switch.
I added if condition from sqlite value 1 to convert to true for switch. Solved.
 
Upvote 0
Top