Android Question Not initialized errors

angelo56

Member
I have a big problem with b4a and the development of an app to control a telescope via bluetooth.
The program is still under development but has no errors, except for the problem I am now describing. At some point in development, many of the globals that declare the views defined in the designer get the "not initialized" error.
I tried every way but I couldn't do anything.
I point out that it is my first attempt to use B4A.
I noticed that by momentarily commenting on line 39 or 64, all the "not initialized" errors disappear. What means?
Please help me, I don't know what to do anymore.
I tried on another PC and it does the same thing.
Sorry for my "google english".
Thank you

Angelo
 

Attachments

  • LX200Control.zip
    76.1 KB · Views: 57

klaus

Expert
Licensed User
Longtime User
The problem is that you try to load layouts with an Integer value (currentPage) instead of a String.
Line 154 : Activity.LoadLayout(currentPage)
B4X:
Sub Activity_Create(FirstTime As Boolean)
    currentPage = 1
    Activity.LoadLayout(currentPage)

The same in line 721.

But for other pages you have written this routine:
B4X:
Sub manageviews
    ' imposta la grafica della pagina indicata in currentPage
    Activity.RemoveAllViews
    Private p As String = currentPage
    Activity.LoadLayout(p)
    If currentPage = 2 Then
        pnlCoordP2.Top = 100dip
    End If
End Sub
Here you transform the integer value of currentPage into a String to load the layout.

Try to replace the two lines Activity.LoadLayout(currentPage) by manageviews.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    currentPage = 1
    manageviews

Unfortunately your page management is not the best.

Anyway, the advice from Erel is the best solution.

Concerning the layouts, it seems that you have setup them for a specific device.
Because you use the 'standard' screen size of 320 x 480, but in your layouts there are views outsides the screen.
Be aware that on other devices with different screen sizes the layouts might not look good.
 
Last edited:
Upvote 1

angelo56

Member
Thanks Erel and Klaus.
Today I tried to implement the B4XPages version of the program, and to correct the "LoadLayout" as suggested. Unfortunately the errors are the same.
B4X:
    currentPage = 1
    Private p As String = currentPage
    Activity.LoadLayout(p)    'before B4XPages transformation

But have you tried commenting the line with the definition of: btnRefreshP2? all errors magically disappear! (except those with instructions referring to the commented button, of course).
I don't see any logic in it.

I can't find a solution!
Please help me

Angelo
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Without seeing what exactly you have done it is impossible to give a concrete advice.
Post your project as you dit in post #1.
To zip a B4XPages, in the IDE on the top of the B4XPages module, press the Ctrl key and click on this line:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=\%PROJECT_NAME%.zip

1695106600701.png
 
Upvote 0

angelo56

Member
I understood where the problem is. In both cases, whether using B4XPages or not, the Activity.LoadLayout (or Root.LoadLayout) statement must have a "literal" parameter. I had a routine that used a variable as "layout name". After corrections I no longer have "uninitialized variable" errors.
Old code:
Sub manageviews
    Root.RemoveAllViews
    Private p As String = currentPage.As(String) 'currentpage is a global
    Root.LoadLayout(p)
End Sub
New code:
Sub manageviews
    ' imposta la grafica della pagina indicata in currentPage
    Root.RemoveAllViews
    Select Case currentPage
        Case 1
            Root.LoadLayout("1")
        Case 2
            Root.LoadLayout("2")
        Case 3
            Root.LoadLayout("3")
        Case 4
            Root.LoadLayout("4")
    End Select
End Sub
Thanks to those who helped me, in any case I converted the program to B4XPages, which is very positive.
Angelo
 
Upvote 0

angelo56

Member
Yes I know. Logically it's the same thing. But probably the precompiler, or the IDE, goes to look for where the page is loaded to put the initializations of the objects that concern it, and looks for the clear name. With a variable he doesn't know which layout he needs to initialize.
This is my guess, but the fact is that the errors are gone.
 
Upvote 0
Top