Android Question Exception: Cannot parse: -1 as boolean

foretek

Member
Licensed User
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
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:
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

foretek

Member
Licensed User
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

foretek

Member
Licensed User
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:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…