Object should first be initialized (Label) error

gehrlekrona

Member
Licensed User
Longtime User
I give up. I have been trying to find information here about the error about initializing a label but can't find anything that helps :(
I have labels in a view that I load using acivity.loadlayout. I have seen replies here about not using the initialize if you have it in a view but I have done both and nothing helps. I started out the project with the GPS sample so I have the lblLat and lblLon.
They are defined in sub globals and I load the
Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
GPS1.Initialize("GPS")
hc.Initialize("hc")
' lblLon.Initialize("lblLon")
' lblLat.Initialize("lblLat")
End If
Activity.LoadLayout("gpsmap")
Activity.LoadLayout("1")


End Sub

Not sure this is enough for anyone to try to find the problem. If not, let me know.
 

gehrlekrona

Member
Licensed User
Longtime User
Init error

You are doing this:
B4X:
Activity.LoadLayout("gpsmap")
Activity.LoadLayout("1")

You can have only 1 layout loaded, which means, after doing that layout "1" is the one running.

Thanks NJDude. Didn't know that BUT even though I have removed one layout, I still get the error when I start the app on my phone. I have the 2 labels, defined in sub globals, creted in the designer and I load the activity with the 2 labels, so where does it come from?
 
Upvote 0

gehrlekrona

Member
Licensed User
Longtime User
Initialize Label Error

You should post your project as a zip file (IDE menu Files / Export As Zip).
So we can see what you have done and how.

Best regards.

Klaus, it is a commercial product so I am not sure how much I can show :(
What I have now is a layout created in the designer. It has 2 labels, a webview and 3 buttons.
I generate the members and add the code to them. In Sub Globals I have this:
Sub Globals
Dim ListView1 As ListView
Dim lblLon As Label
Dim lblLat As Label
Dim Button1 As Button
Dim Button2 As Button
Dim hc As HttpClient
Dim strURL As String
Dim WebView1 As WebView
Dim Button3 As Button
End Sub

In Activity_Create I have this after my last try:
Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
GPS1.Initialize("GPS")
hc.Initialize("hc")
End If
lblLon.Initialize("lblLon")
lblLat.Initialize("lblLat")

Activity.LoadLayout("gpsmap")
End Sub

When I open the app on my phone I get:
"An error has occured in the sub: main_globals (java line:416) java.lang.RuntimeException: Object should first ne initialized (Label). Continue?"
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If you are using the designer, these 2 lines are unnecessary:
B4X:
lblLon.Initialize("lblLon")
lblLat.Initialize("lblLat")

Views created with the designer are automatically initialized.
 
Upvote 0

gehrlekrona

Member
Licensed User
Longtime User
Initialize Label error

If you are using the designer, these 2 lines are unnecessary:
B4X:
lblLon.Initialize("lblLon")
lblLat.Initialize("lblLat")

Views created with the designer are automatically initialized.

Thanks NJDude!
I have tried both with and without. I did solve the problem though, and that was removing the labels altogether ans just use string to hold the value instead. I stil would like to know, and I have seen other asking the same question here, why it is happening. I don't see any reason for it.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Try running in debugging mode and check at which specific label you get the error.
 
Upvote 0

Kight Riot

Member
Licensed User
Longtime User
Possible Solution

Not sure if this would help in any way after so long, but I was having the same issue with the "Object should first be initialized (Label) error".

I had created everything from scratch and mid way through, renamed the layout. No big deal, but I forgot to change it in the "Activity.LoadLayout("Layout1") " spot. So all the changes after weren't showing up on the layout because I was still referencing the old layout name.

I was really confused there for a few minutes because there were a bunch of labels that I had made before the layout was renamed that were still working.

Anyways, though it may have been too late for you, it might be some help to someone else.

Kight
 
Upvote 0

Pintinho

Member
Licensed User
Longtime User
Label - object should be first initialized proble

Hi,
I had the same problem: I was definining labels on the designer and then trying to change some proprieties of these labels dynamically. And I got this same error.

Then I realised that I was trying to change the proprieties of these lables BEFORE I actually uploaded the layout - hence the initialise error. I change the order - loadlayout first, change proprieties after - and I did not have the error.
 
Last edited:
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I have same problem. But If I load layout of the labels, main layout will be not be visible. This is first problem. And second problem is gps values always should be sent to the server. So, Gps values screen always will be open? No, of course. So what should I do? I should remove labels from designer and initialize in Activity_Create? But in this case how I will show these labels on the screen?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
this is a REALLY OLD THREAD.
Please create a NEW THREAD for EACH question.
 
Upvote 0
Top