Android Question java language runtime exceptions: Object should first be initialized

Pavan Krishna Mulpur

Member
Licensed User
Longtime User
Dear all,

I am executing the Second Program from B4A Beginners Guide V3.0 after entering the code on page 53. When I compile and execute the program I get the error that says,
"java.lang.RuntimeExceptions: Object should first be initialized (Label). The screen shot of the same error is attached to this post.
Apart from that I also get a warning message as shown below:

I've few questions based on this warning.

1. How and where do I initialize a variable in my code? In my code this is what I have under Sub Globals and there is a wavy line under Private lblResult As Label. I guess there is some thing wrong with this line. Please explain what is wrong here.

Sub Globals
Public Number1, Number2 As Int
Private lblResult As Label
Private lblComments As Label
Private lblMathSign As Label
Private lblNumber1 As Label
Private lblNumber2 As Label
Private btnAction, btn0 As Button
End Sub Globals

2. Same doubt from btn0 also. How do I initialize btn0?

3. With respect to the warning Sub 'CheckResult1' is not used. I understand I've not used it any where but I renamed CheckREsult to CheckResult1 as when I was compiling the code I got an error message that duplicate value of CheckResult. Hence I renamed the second CheckResult to CheckResult1 and then it got executed successfully.

upload_2016-3-21_5-46-43.png


Please help me by answering my queries.

Thank you.

Regards,

Pavan Krishnaa
 

Attachments

  • Java object should be initialized.pdf
    230.7 KB · Views: 215

Pavan Krishna Mulpur

Member
Licensed User
Longtime User
Hi Erel,

Please find attached the zip file of the SecondProgram that I created.

Thank you.

Regards,

Pavan.
 

Attachments

  • secondprogram.zip
    11.1 KB · Views: 163
Upvote 0

Pavan Krishna Mulpur

Member
Licensed User
Longtime User
Dear Erel,

I was under the impression that the line Private lblResult As Label under sub Globals, in the Main layout file is the one that declares the view lblresult. If that's wrong can you please explain how do I initialize the view lblResult. Because in the folder MyB4A Programs I've a sub folder called Second Program and within it I'v files main_label.bal, main1.bal, SecondProgram.b4A, SecondProgram.b4a.b4a.meta, SecondProgram.b4a.meta, SecondProgram.bal.

Is it something I do from Visual Designer. Here I opened the file SecondProgram went to WYSIWYG Designer -> Connect and then selected all the views available. Then went to Tools menu and hit on Generate Members. The layout of the second program appeared on my mobile phone but when I try to click on Enter or any button on the mobile, it just gets selected. Nothing happens.

Please explain.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top