Error when running my application.

billy047

Member
Licensed User
Longtime User
Hello, everyone, good day.:sign0085:
When test and debug with the emulator or my phone samsung i9100 galaxy s II, all good, but when I get out of the development environment and run my application in my galaxy (No matter if I install the application directly from a folder of the phone or I run the version of the installation that stay in my galaxy after testing), I get a window with the error "An error has occurred in sub : main_pontotmovs (java line: 1531) java.lang.RuntimeException: Object Should be initialized first (Label). Continue? ". Then I Press NO CONTINUE, and rerun it, no longer gives the error. I try to run once more and the same error reappears. That is, every time I run the error alternates. appears once and the next not. I've been looking and can not find the cause.

Here the code where it operates mi Sub pontotmovs, as you can see is a label which is assigned the value of a counter movement.

Sub Process_Globals
'... more code
Dim NumMovim,CantSegs As Int
'... more code
End Sub

Sub Globals
'... more code
Dim lblNumMovs, lblnMovs, lblSeg, lblSegTit, lblMuestra, lblVer, lblAyuda1 As Label
'... more code
End Sub

Sub Activity_Create(FirstTime As Boolean)
If firsttime = True Then
'... more code
NumMovim=0
PonTotMovs
'... more code
End If
End Sub

Sub MuestraTablero
PonTotMovs
'... more code
End Sub
Sub MueveNumero(elValor As Byte, elTag As String)
'... more code
NumMovim=NumMovim+1
'... more code
End Sub

Sub PonTotMovs
lblnMovs.Text = NumMovim
End Sub

My application is a puzzle I want to put to market, but just need to correct this error. Currently my code is about 700 lines.

Thanks in advance for any indication of what I might be doing wrong and I do not see.

Guillermo
 

klaus

Expert
Licensed User
Longtime User
How do you add your views ?
By code or with a layout file.
The error indicates that your label lblnMovs was not initialized.
- If you add the views by code you need to initialize the view and then to add it to the activity or to a panel.
- If you add the views with a layout file, check the spelling of the label in the layout.

Best regards.
 
Upvote 0

billy047

Member
Licensed User
Longtime User
Thank you Klaus, for your quick response, my label is with layout file, before asking for help, I tried changing the name, change of position and the error is the same.

I see that the spelling is ok, as you see in the attached gif.

The funny thing is that the test also does not fail and when I run out of ide, gives the error once and not again, again and once again if not, or alternately, sometimes it takes as initialized.

I'm confused.

thanks
 

Attachments

  • lblnMovs.gif
    lblnMovs.gif
    4.8 KB · Views: 214
Upvote 0

billy047

Member
Licensed User
Longtime User
OK Klaus, I sent you this code, with which it happens to me the error. runs fine once, but the other generates the error, and so on.

Thanks in advance for your interest and support.

Guillermo
 

Attachments

  • Hits02.zip
    33.6 KB · Views: 200
Upvote 0

klaus

Expert
Licensed User
Longtime User
It's normal that your application raises an error depending on the resolution of the device. In your code you load the layout file only if the resolution is 480 * 800 and if FirstTime = True.
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Activity_Create(FirstTime [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Boolean[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] firsttime = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]    lv = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]GetDeviceLayoutValues[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (lv.width=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]480[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]AND[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (lv.height=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]800[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]AND[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (lv.Scale=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1.5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]      activity.LoadLayout([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"lay480x800s15"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]    Timer1.Initialize([/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"timer1"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    NumMovim=[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]    PonTotMovs[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    Activity.Title = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"GCM "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] & ProgName & ProgVersion & ProgDate[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]  ShowHit[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

You should:
- move Activity.LoadLayout outsides the FirstTime = True test.
You could:
- add a default layout file for the other resolutions.
- use different variants in one layout file.
- limit to portrait orientation only if you don't want the landscape orientation.

You can also simplify the code of the ImageView Click events, replace the 15 routines by one. Using the Tag parameter of the ImageViews. Attached the modified code.
The routines ShowHit and PonTotMovs could be one routine, but this is perhaps due to the reduced project.

Best regards.
 

Attachments

  • Hits02_New.zip
    33.6 KB · Views: 188
Upvote 0

billy047

Member
Licensed User
Longtime User
Klaus OK, thank you for your interest, support, time and orientation, OK The code I sent you was minimal, just so I could see the error. I already understood that I should not put the detection of the resolution only in the first . as you put it in the code you sent me, thank you for teach me the use of the sender and thus make more compact and efficient code. :sign0098:

Normally I program in visual basic Net 2008 - 2010 and there use the Handles to link all the buttons, but here in B4A at the time I spend had not yet found how. I really thank you very much.

Would be nice to have a tutorial with programming techniques and best practices.

I have to make changes in my code with your suggestions.

Thanks again and best regards
 
Upvote 0

billy047

Member
Licensed User
Longtime User
Klaus, actually have not seen it but I will see. I also need to know is the cycle that follows the application, when running each of the parts of the activity, that is, create, resume, pause and so on, because it is clear that this error happened to me because I do not know this cycle, when enters or run the activity_create. In short, I need to devote more time to learn and get juice.

Once again thank you very much

Guillermo
 
Upvote 0
Top