Bug? Strange Boolean error

Daestrum

Expert
Licensed User
Longtime User
this is the error logged

Program started.
(Boolean) false
Error occurred on line: 19 (main).
java.lang.RuntimeException: Cannot parse: (Boolean) false as boolean
at anywheresoftware.b4a.BA.parseBoolean(BA.java:270)
at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:339)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:469)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:209)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:69)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:33)
at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:331)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:297)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)

these are lines that produced it
B4X:
 private inetaddress as JavaObject
.....
.....
    'works
    Log(inetaddress.InitializeStatic("java.net.InetAddress").RunMethodJO("getByName",Array As String("www.hjhkahkd.co.uk")).RunMethodJO("isReachable",Array As Object(2000)))
    'strange error
    If inetaddress.InitializeStatic("java.net.InetAddress").RunMethodJO("getByName",Array As String("www.hjhkahkd.co.uk")).RunMethodJO("isReachable",Array As Object(2000)) Then
        Log("reachable")
    Else
        Log("unreachable")
    End If
 

stevel05

Expert
Licensed User
Longtime User
In java terms the object Boolean is different to the primitive 'boolean'.

What happens if you do:

B4X:
Dim B As Boolean
B = inetaddress.InitializeStatic("java.net.InetAddress").RunMethodJO("getByName",ArrayAsString("www.hjhkahkd.co.uk")).RunMethodJO("isReachable",ArrayAsObject(2000))

If B Then
Log("reachable")
. etc.
 

stevel05

Expert
Licensed User
Longtime User
It failed, I've checked, you'll need to do something like:

B4X:
 If inetaddress.RunMethodJO("getByName",Array As String("www.hjhkahkd.co.uk")).RunMethodJO("isReachable",Array As Object(2000)).RunMethod("booleanValue",Null) Then
 

Daestrum

Expert
Licensed User
Longtime User
its odd that
B4X:
......RunMethod("booleanValue",Null)
works as expected but
B4X:
......RunMethodJO("booleanValue",Null)
still produces the error
 

stevel05

Expert
Licensed User
Longtime User
It's getting late!

B4X:
If inetaddress.RunMethodJO("getByName",Array As String("www.hjhkahkd.co.uk")).RunMethod("isReachable",Array As Object(2000)) Then

works too.

RunmethodJO returns a JavaObject containing the value whereas Runmethod returns the value.
 
Top