Android Question java.lang.RuntimeException: Object should first be initialized (B4XView).

Maxjonz

New Member
Hi
As a newbie to BxA I entered the example program as instructed and compiled it. However I keep getting the error message "java.lang.RuntimeException: Object should first be initialized (B4XView). " when I complie it . It appears that there is a problem on Line 39 (see code below) , but I think that I have entered it all correctly.
I have put the line numbers in for clarity
Private Sub NewProblem
36 Number1 = Rnd(1,10)
37 Number2 = Rnd(1,10)
38 lblNumber1.Text = Number1
39 lblNumber2.Text = Number2
40 lblComments.text = "Enter the result" & CRLF & "and click on OK"
41 edtResult.Text = ""
42
End Sub

The first part of the red error messages reads as follows.

Logger connected to: motorola moto g15
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 39 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:213)
at anywheresoftware.b4a.objects.B4XViewWrapper.setText(B4XViewWrapper.java:229)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)

Can anyone please help me with a possible solution to this error ?
 

klaus

Expert
Licensed User
Longtime User
Did you also declare
Private lblNumber2 As B4XView
in the Class_Globals routine ?

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private btnAction As B4XView
    Private edtResult As B4XView
    Private lblComments As B4XView
    Private lblMathSign As B4XView
    Private lblNumber1 As B4XView
    Private lblNumber2 As B4XView
    
    Private Number1, Number2 As Int
End Sub
 
Upvote 0
Top