Error in Guide 1.8 tutorial pdf - Tutorial 2

mystic7

Member
I did the first calculator tutorial with no problems. On the second one, it's throwing a java runtime error on this section of code:

B4X:
Sub New
Number1 = Rnd(1, 10)
Number2 = Rnd(1, 10)
lblNumber1.Text = Number1
lblNumber2.Text = Number2
lblComments.Text = "Enter the result" & CRLF & "and click on OK"
lblComments.Color = Colors.RGB(128,128,255)
lblResult.Text = ""
btn0.Visible = False
End Sub

The line lblNumber1.Text = Number1 gives the error "Object should first be initialized (Label). My code matches that in the tutorial exactly. Any ideas what could be causing this error?

UPDATE: I matched my code against the code in the source files and they're exactly the same except for two lines that are not included in the tutorial but wouldn't be the cause of this error message. Anyway, after adding the two lines, the code matches exactly, yet the source code version runs smoothly and my version throws the error message I mentioned above. How can this be?
 
Last edited:

pluton

Active Member
Licensed User
Longtime User
What debuger says? "Object should first be initialized (Label)"

Did you create lblNumber1 with designer?
Did you pick from designer Tools - Generate Members?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Are you sure that the Label is spelled correctly in the Designer and in the Globals subroutine?
If you have B4A version 1.8 lblNumber1 should be displayed in red showing that the Label variable has not been declared.
I just tested the source code from version 1.6 of the Beginner's Guide and it works without any error.

Best regards.
 
Upvote 0

pbmjoe

Member
Licensed User
Longtime User
SecondProgram in tutorial in v1.8

I have a problem with the Sub Globals
Sub Globals
Dim Number1, Number2 As int

Sub New
Number1 = Rnd(1,10)
Number2 = Rnd(1,10)

Sub CheckResult
Number1 & Number2 are not Set
These Variables Return 0

Can you Help?
Regards
pbmjoe
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You are probably missing the call to New in the Activity_Create routine
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    New
End Sub
You could compair your code to the code in the SourceCode folder you got with the Beginner's Guide.

Best regards.
 
Upvote 0

pbmjoe

Member
Licensed User
Longtime User
:sign0013: My problem with Globals was due to typing all the code and not using the As pop-up list to select required int. The program now works OK.
Thank You for an excellent IDE. Regards pbmjoe
 
Upvote 0
Top