F foretek Member Licensed User Dec 19, 2019 #1 My project use Bluetooth. I port a working code from VB to B4A. When data in Bluetooth communication, I received "Exception: Cannot parse: -1 as boolean" error at (java line 1501). Total code has 1109 line in B4A. Here is the message. Any help? Thank you.
My project use Bluetooth. I port a working code from VB to B4A. When data in Bluetooth communication, I received "Exception: Cannot parse: -1 as boolean" error at (java line 1501). Total code has 1109 line in B4A. Here is the message. Any help? Thank you.
drgottjr Expert Licensed User Longtime User Dec 19, 2019 #2 it is not unusual to incorrectly use the result of an operation as a boolean. as an example, a string compare returns an integer, not true/false. this code will throw the error you see: B4X: Expand Collapse Copy if name.compareTo("foretek") then ' <<<< compareTo() returns an int, not a boolean log("hello, " & name) else log("you are not foretek") end if in this example, the correct syntax is: if name.compareTo("foretek") = 0 then... see if any operations that you are using to determine true or false actually return an integer. there is a hint in the error message: your sub rxprocess Upvote 0
it is not unusual to incorrectly use the result of an operation as a boolean. as an example, a string compare returns an integer, not true/false. this code will throw the error you see: B4X: Expand Collapse Copy if name.compareTo("foretek") then ' <<<< compareTo() returns an int, not a boolean log("hello, " & name) else log("you are not foretek") end if in this example, the correct syntax is: if name.compareTo("foretek") = 0 then... see if any operations that you are using to determine true or false actually return an integer. there is a hint in the error message: your sub rxprocess
F foretek Member Licensed User Dec 19, 2019 #3 Thanks for replying. I only have one Sub that uses Boolean as return. I changed its return as Int, returns 0, or 1. Also changed its calling routine. That part works fine. I still get the "Cannot parse: -1 as boolean" error. Is there any way I can look into java line 1501 to find out which B4A statement causes this? Upvote 0
Thanks for replying. I only have one Sub that uses Boolean as return. I changed its return as Int, returns 0, or 1. Also changed its calling routine. That part works fine. I still get the "Cannot parse: -1 as boolean" error. Is there any way I can look into java line 1501 to find out which B4A statement causes this?
DonManfred Expert Licensed User Longtime User Dec 19, 2019 #4 foretek said: Is there any way I can look into java line 1501 to find out which B4A statement causes this? Click to expand... sure. look at the generated java sources. Objects\src\*.* (search for the main.java) Upvote 0
foretek said: Is there any way I can look into java line 1501 to find out which B4A statement causes this? Click to expand... sure. look at the generated java sources. Objects\src\*.* (search for the main.java)
klaus Expert Licensed User Longtime User Dec 19, 2019 #5 Couldn't you test your program in Debug mode? Then the compiler will stop at the code line with the error. Upvote 0
Couldn't you test your program in Debug mode? Then the compiler will stop at the code line with the error.
F foretek Member Licensed User Dec 19, 2019 #6 Hi, Klaus. I am new. Your suggestion is what I need. I found the problem. I use a received byte from bluetooth to assign to a checkbox1.Checked to turn it on/off with value 255 or 0. The received byte value 255 becomes -1 in B4A. When -1 is assigned to checkbox1.Checked, it generate the "Cannot parse: -1 as boolean" error. Thanks for all your helps. Last edited: Dec 19, 2019 Upvote 0
Hi, Klaus. I am new. Your suggestion is what I need. I found the problem. I use a received byte from bluetooth to assign to a checkbox1.Checked to turn it on/off with value 255 or 0. The received byte value 255 becomes -1 in B4A. When -1 is assigned to checkbox1.Checked, it generate the "Cannot parse: -1 as boolean" error. Thanks for all your helps.
klaus Expert Licensed User Longtime User Dec 19, 2019 #7 Maybe a routine like this could help to convert: B4X: Expand Collapse Copy Sub IntToBoolean(Value As Int) As Boolean If Value = 0 Then Return False Else Return True End If End Sub Upvote 0
Maybe a routine like this could help to convert: B4X: Expand Collapse Copy Sub IntToBoolean(Value As Int) As Boolean If Value = 0 Then Return False Else Return True End If End Sub