Android Question Did you forget to call Activity.LoadLayout

DataProtec

Member
Licensed User
Hello
I was working fine with Project, but then got the error message fom the compiler "Did you forget to call Activity.LoadLayout?"
I did no changes in the Layout, the Layout is set in the Programm
Also if i start a new empty Project, only sabe and upload get the sam Msg
What can be the problem
Uli DataProTec
 

DonManfred

Expert
Licensed User
Longtime User
You are not providing enough informations.
Upload a small project which shows the issue. Use File-Export as zip from the IDE to Export the project.

Edit to add: dammit; Erel was faster...
 
Upvote 0

DataProtec

Member
Licensed User
Here the full Log

Logger connected to: bq Aquaris V Plus
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
Error occurred on line: 19 (Starter)
java.lang.RuntimeException: Object should first be initialized (EditText).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
at anywheresoftware.b4a.objects.EditTextWrapper.setText(EditTextWrapper.java:226)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.initializeGlobals(main.java:320)
at b4a.example.main.afterFirstLayout(main.java:101)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
** Activity (main) Create, isFirst = true **
*** Service (starter) Create ***
** Service (starter) Start **
Error occurred on line: 19 (Starter)
java.lang.RuntimeException: Object should first be initialized (EditText).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
at anywheresoftware.b4a.objects.EditTextWrapper.setText(EditTextWrapper.java:226)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.initializeGlobals(main.java:320)
at b4a.example.main.afterFirstLayout(main.java:101)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
** Activity (main) Create, isFirst = true **
*** Service (starter) Create ***
** Service (starter) Start **
Error occurred on line: 19 (Starter)
java.lang.RuntimeException: Object should first be initialized (EditText).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
at anywheresoftware.b4a.objects.EditTextWrapper.setText(EditTextWrapper.java:226)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.initializeGlobals(main.java:320)
at b4a.example.main.afterFirstLayout(main.java:101)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
** Activity (main) Create, isFirst = true **

The Layout is set
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Client_Layout")  '<--- and exist, the file
End Sub
 
Upvote 0

DataProtec

Member
Licensed User
Here the complete code
B4X:
#AdditionalJar: jtds-1.3.1.jar

Sub Process_Globals
    Public msSQL As JdbcSQL
    Private driver As String = "net.sourceforge.jtds.jdbc.Driver"
    Private jdbcUrl As String = "jdbc:jtds:sqlserver://192.168.5.215:1433/DB_Garbaman"
    Private Username As String = "user"
    Private Password As String = "1234"
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private txtUserName As EditText
    Private txtPassword As EditText
    txtUserName.Text = ""
    txtPassword.Text = ""
        
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Client_Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub cmdConnect_Click
    If txtUserName.Text = "" Or txtUserName.text = "txtUserName" Then
        Msgbox("Falta nombre de usuario", "Atención")
        txtUserName.RequestFocus
        Return
        End If
    
    If txtPassword.Text = "" Or txtPassword.text = "txtPassword" Then
        Msgbox("Falta la contraseña", "Atención")
        txtPassword.RequestFocus
        Return
    End If
            
    
    msSQL.InitializeAsync("msSQL", driver, jdbcUrl, Username, Password)
    
    Wait For msSQL_Ready (Success As Boolean)
    If Success = True Then
        Log("Connected")
    End If
    
    
    'Dim rs As JdbcResultSet = msSQL.ExecQuery("SELECT EMail, Name FROM UserInfo_Table WHERE UserID = 5")
    Dim rs As JdbcResultSet = msSQL.ExecQuery("SELECT UserID, Name FROM UserInfo_Table WHERE EMail = '" & txtUserName.Text & "'")
    Do While rs.NextRow
        Log(rs.GetString2(0))
        Log(rs.GetString2(1))
    Loop
    rs.Close
    
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private txtUserName As EditText
    Private txtPassword As EditText
    txtUserName.Text = ""
    txtPassword.Text = ""
        
End Sub

you are trying to access the editfields before you load the layout!

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private txtUserName As EditText
    Private txtPassword As EditText
    
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Client_Layout")
    txtUserName.Text = ""
    txtPassword.Text = ""

End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
also if i créate a New projetc without anything get the same error

1. The error must be another then before. Post the full error!

2. same applies to the process global

You are NOT allowed to change any vars at this time or to set the value. SET it in activity_create

B4X:
Sub Process_Globals
    Public msSQL As JdbcSQL
    Private driver As String
    Private jdbcUrl As String
    Private Username As String
    Private Password As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private txtUserName As EditText
    Private txtPassword As EditText
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Client_Layout")
    txtUserName.Text = ""
    txtPassword.Text = ""
    driver = "net.sourceforge.jtds.jdbc.Driver"
    jdbcUrl = "jdbc:jtds:sqlserver://192.168.5.215:1433/DB_Garbaman"
    Username = "sa"
    Password = "@Xmallahi"

End Sub

PS: Please use quote tags when posting logs or errors.
 

Attachments

  • DPNnew.zip
    10 KB · Views: 128
Last edited:
Upvote 0

DataProtec

Member
Licensed User
sorry did not now this, i copied what i saw in other Threads
Also get a message must initilize the Object, but is done
 

Attachments

  • line81.png
    line81.png
    29 KB · Views: 135
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0
Top