P Penko Active Member Licensed User Longtime User Mar 20, 2012 #1 Dear Erel! I found out that If(i Mod 2) doesn't produce any B4A compiler error, neither does it fail the java compilation. This error occurs when I start my application: An error occured in sub:******** (java line: xxx). java.lang.RuntimeException: Cannot parse: 0 as boolean. For the ones like me who didn't understand at first, the correct syntax is: i Mod 2 = 0. I couldn't understand where do I have booleans in my code so I opened the java file and found the following: Code: Copy if (BA.ObjectToBoolean((_i%2))) { If I correct the B4A syntax, I get this: (which is pretty much better and valid) Code: Copy if ((_i%2==0)) { Erel, please check it out as others may encounter it too. A kind of suggestion, you may also add if(i Mod 2) to default to = 0 ) Hope this report helps.
Dear Erel! I found out that If(i Mod 2) doesn't produce any B4A compiler error, neither does it fail the java compilation. This error occurs when I start my application: An error occured in sub:******** (java line: xxx). java.lang.RuntimeException: Cannot parse: 0 as boolean. For the ones like me who didn't understand at first, the correct syntax is: i Mod 2 = 0. I couldn't understand where do I have booleans in my code so I opened the java file and found the following: Code: Copy if (BA.ObjectToBoolean((_i%2))) { If I correct the B4A syntax, I get this: (which is pretty much better and valid) Code: Copy if ((_i%2==0)) { Erel, please check it out as others may encounter it too. A kind of suggestion, you may also add if(i Mod 2) to default to = 0 ) Hope this report helps.
J Jost aus Soest Active Member Licensed User Longtime User Mar 20, 2012 #2 Somewhere in the b4a information it's written (IMHO), that the boolean "True" is not the same like "<>0", as we VB-users are used to use. Last edited: Mar 20, 2012 Upvote 0
Somewhere in the b4a information it's written (IMHO), that the boolean "True" is not the same like "<>0", as we VB-users are used to use.
klaus Expert Licensed User Longtime User Mar 20, 2012 #3 If you write If i Mod 2 Then expects a Boolean. But the result of is a number therefor it raises an error. Writing If i Mod 2 = 0 Then is OK because i Mod 2 = 0 gives a Boolean as result ! There is no numeric equivalent in B4A for Booleans. Best regards. Upvote 0
If you write If i Mod 2 Then expects a Boolean. But the result of is a number therefor it raises an error. Writing If i Mod 2 = 0 Then is OK because i Mod 2 = 0 gives a Boolean as result ! There is no numeric equivalent in B4A for Booleans. Best regards.
P Penko Active Member Licensed User Longtime User Mar 21, 2012 #4 Thanks for the clarification, Klaus. Maybe Erel will anyway prevent the compiler from allowing this. Sent from my HTC Desire using Tapatalk Upvote 0
Thanks for the clarification, Klaus. Maybe Erel will anyway prevent the compiler from allowing this. Sent from my HTC Desire using Tapatalk