Android Question Error Help? Java Exception at line 0. code included(SOLVED)

Stichler

Active Member
Licensed User
I am unsure why I am getting this error. Any help please?

Error occurred on line: 0 (Practice_addition1s)
java.lang.RuntimeException: Cannot parse: 8 as boolean
at anywheresoftware.b4a.BA.parseBoolean(BA.java:607)
at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:677)
at b4a.example.practice_addition1s._question1(practice_addition1s.java:443)
at b4a.example.practice_addition1s._activity_create(practice_addition1s.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.practice_addition1s.afterFirstLayout(practice_addition1s.java:104)
at b4a.example.practice_addition1s.access$000(practice_addition1s.java:17)
at b4a.example.practice_addition1s$WaitForLayout.run(practice_addition1s.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 

Stichler

Active Member
Licensed User
ok here is all code leading into the error from previous activity:

B4X:
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private btnAdd10s As Button
    Private btnAdd1s As Button
    Private btnAdd2s As Button
    Private btnAdd3s As Button
    Private btnAdd4s As Button
    Private btnAdd5s As Button
    Private btnAdd6s As Button
    Private btnAdd7s As Button
    Private btnAdd8s As Button
    Private btnAdd9s As Button
    Private btnAddMix As Button
    Private btnBack As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Practice_Addition")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnBack_Click
    Activity.Finish
    StartActivity(Practice_Menu)
End Sub

Sub btnAddMix_Click
  
End Sub

Sub btnAdd9s_Click
  
End Sub

Sub btnAdd8s_Click
  
End Sub

Sub btnAdd7s_Click
  
End Sub

Sub btnAdd6s_Click
  
End Sub

Sub btnAdd5s_Click
  
End Sub

Sub btnAdd4s_Click
  
End Sub

Sub btnAdd3s_Click
  
End Sub

Sub btnAdd2s_Click
  
End Sub

Sub btnAdd1s_Click
    Activity.Finish
    StartActivity(Practice_Add1s)
End Sub

Sub btnAdd10s_Click

   End Sub
Here Is The Error:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (practice_menu) Create, isFirst = true **
** Activity (practice_menu) Resume **
** Activity (practice_menu) Pause, UserClosed = true **
** Activity (practice_addition) Create, isFirst = true **
** Activity (practice_addition) Resume **
** Activity (practice_addition) Pause, UserClosed = true **
** Activity (practice_add1s) Create, isFirst = true **
Error occurred on line: 0 (Practice_Add1s)
java.lang.RuntimeException: Cannot parse: 3 as boolean
at anywheresoftware.b4a.BA.parseBoolean(BA.java:607)
at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:677)
at b4a.example.practice_add1s._question1(practice_add1s.java:439)
at b4a.example.practice_add1s._activity_create(practice_add1s.java:370)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.practice_add1s.afterFirstLayout(practice_add1s.java:104)
at b4a.example.practice_add1s.access$000(practice_add1s.java:17)
at b4a.example.practice_add1s$WaitForLayout.run(practice_add1s.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (practice_add1s) Resume **

a different Number is being passed as Boolean for some reason, but makes no sense as obviously numbers are not Boolean and I do not know where it is being called from
 
Last edited:
Upvote 0

Stichler

Active Member
Licensed User
The odd thing is sometimes this error fires and sometimes it does not. Does it have to do with activities closing and starting? I am seriously confused. Should also note that when it does fire it closes out application. Also there is no line 0 with code
 
Upvote 0

udg

Expert
Licensed User
Longtime User
** Activity (practice_add1s) Create, isFirst = true **
Error occurred on line: 0 (Practice_Add1s)
Those two lines indicate the error occurring in PracticeAdd1 activity. Check it carefully.
 
Upvote 0

Stichler

Active Member
Licensed User
Ok i have searched and searched I can not find anything that should be producing this error! Please help! Here is code from that activity:

B4X:
#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private QuestionNumber As Int
    Private WrongAnswers As Int
    Private CorrectAnswers As Int
 

    Private imgLine As ImageView
    Private lblAddNumber1 As Label
    Private lblAddNumber2 As Label
    Private lblPlusSign As Label
    Private btnAnswer1 As Button
    Private btnAnswer2 As Button
    Private btnAnswer3 As Button
    Private btnAnswer4 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Practice_Add1s")

    Main.MP.Stop
    Question1
     
 
 
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Question1
    QuestionNumber = 1
    Main.MP.Load(File.DirAssets, "1+1.wav")
    Main.MP.Play
    lblAddNumber1.Text = "1"
    lblAddNumber2.Text = "1"
 
    Dim Answer1 As Int
    Dim Answer2 As Int
    Dim Answer3 As Int
    Dim Answer4 As Int
 
    Answer1 = 2
 
    Answer2 = Rnd(1, 11)
    If Answer2 = 2 Then
        Do While Answer2 = 2
            Answer2 = Rnd(1, 11)
        Loop
    End If
 
    Answer3 = Rnd(1, 11)
    If Answer3 = 2 Or Answer3 = Answer2 Then
        Do While Answer3 = 2 Or Answer2
            Answer3 = Rnd(1, 11)
        Loop
    End If
 
    Answer4 = Rnd(1, 11)
    If Answer4 = 2 Or Answer4 = Answer2 Or Answer4 = Answer3 Then
        Do While Answer3 = 2 Or Answer2 Or Answer3
            Answer3 = Rnd(1, 11)
        Loop
    End If
 
    Dim RandomAnswers As Int
 
    RandomAnswers = Rnd(1, 5)
 
    Select RandomAnswers
        Case 1
            btnAnswer1.Text = Answer1
            btnAnswer2.Text = Answer2
            btnAnswer3.Text = Answer3
            btnAnswer4.Text = Answer4
        Case 2
            btnAnswer1.Text = Answer2
            btnAnswer2.Text = Answer3
            btnAnswer3.Text = Answer4
            btnAnswer4.Text = Answer1
        Case 3
            btnAnswer1.Text = Answer3
            btnAnswer2.Text = Answer4
            btnAnswer3.Text = Answer1
            btnAnswer4.Text = Answer2
        Case 4
            btnAnswer1.Text = Answer4
            btnAnswer2.Text = Answer1
            btnAnswer3.Text = Answer2
            btnAnswer4.Text = Answer3
    End Select
 
End Sub


Sub btnAnswer4_Click
    Select QuestionNumber
        Case 1
     
    End Select
End Sub

Sub btnAnswer3_Click
    Select QuestionNumber
        Case 1
     
    End Select
End Sub

Sub btnAnswer2_Click
    Select QuestionNumber
        Case 1
         
    End Select
End Sub

Sub btnAnswer1_Click
    Select QuestionNumber
        Case 1
     
    End Select
End Sub
here is error:

Logger connected to: samsung SM-G950U
--------- beginning of main
Copying updated assets files (18)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (practice_menu) Create, isFirst = true **
** Activity (practice_menu) Resume **
** Activity (practice_menu) Pause, UserClosed = true **
** Activity (practice_addition) Create, isFirst = true **
** Activity (practice_addition) Resume **
** Activity (practice_addition) Pause, UserClosed = true **
** Activity (practice_add1s) Create, isFirst = true **
Error occurred on line: 0 (Practice_Add1s)
java.lang.RuntimeException: Cannot parse: 1 as boolean
at anywheresoftware.b4a.BA.parseBoolean(BA.java:607)
at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:677)
at b4a.example.practice_add1s._question1(practice_add1s.java:439)
at b4a.example.practice_add1s._activity_create(practice_add1s.java:370)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.practice_add1s.afterFirstLayout(practice_add1s.java:104)
at b4a.example.practice_add1s.access$000(practice_add1s.java:17)
at b4a.example.practice_add1s$WaitForLayout.run(practice_add1s.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (practice_add1s) Resume **
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Do While Answer3 = 2 Or Answer2
Shouldn't it be:
Do While ((Answer3 = 2) Or (Answer3 =Answer2))
?
Similarly in Answer4 code loop.

Another way to write code with similar goal could be to keep track of already randomly selected numbers and discard repetitions. Think about an array of 10 bytes; when you randomly select a candidate you first check it against the array and if not used than assign it to next Answer variable and mark it accordingly in the array.
As an additional measure, having AnswerX vars defined as an array will let you do all the "init" in a for-next loop.
 
Last edited:
Upvote 0

Stichler

Active Member
Licensed User
Ty so much, such a terrible miss on my part. Still learning. Can you tell me why the error was at line 0 and not the line where code was wrong?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Can you tell me why the error was at line 0
Sorry,no. This one is for Erel...ora any other real Expert.
 
Upvote 0

Stichler

Active Member
Licensed User
uhhh i'm sorry I can't I actually deleted that project and started a different one. very sorry so late with a reply
 
Upvote 0
Top