Android Question java.lang.RuntimeException: Object should first be initialized (EditText).

Rotterdamse Adje

Member
Licensed User
Longtime User
After upgrading B4A to the latest version 10.7 (and after following the guidelines related to java downloads etc) I'm trying to re-build my existing (commercial) project.
After solving problems with the NET library (to be able to use FTP) and after renaming the MsgBox to MsgBoxAsync The project is compiling (in debug mode).
But when i'm try to run it with B4A-Bridge, the following errors occurred :
Error occurred on line: 140 (Main)
java.lang.RuntimeException: Object should first be initialized (EditText).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.TextViewWrapper.getText(TextViewWrapper.java:36)
- and 21 errorlines more -
In the current version of the app, i've declared:
Sub Globals
Dim etxtEmailadres As EditText
Dim etxtPassword As EditText
....
End Sub
And the Activity.LoadLayout("myForm") of the related form is in the Sub Activity_Create(FirstTime As Boolean)

The errorline is in the :
137 Sub Activity_Pause (UserClosed As Boolean)
138
139
āž”140 glUserid = etxtEmailadres.Text.ToLowerCase
141 glPassword = etxtPassword.Text.ToUpperCase
142 End Sub
What is wrong?
 

Rotterdamse Adje

Member
Licensed User
Longtime User
On the previous version of B4A there was no single problem with building the app, the .APK works fine on Android Phones, the old build still works.
With the new version, the error I receive now is:
ToonOmzet - 9: Cannot access activity object from sub Process_Globals.
B4X:
6 Sub Process_Globals
7  'These global variables will be declared once when the application starts.
8    'These variables can be accessed from all modules.
9    Dim glLiveOmzet As LiveOmzet
10    'Dim tempPathFile As String
11      Dim Timer1 As Timer
12    Dim glFTPPassword As String
13    Dim FTP As FTP
14 End Sub
LiveOmzet is a class module to communicate with the screen on the Android phone. In the previous version it was not a problem. Where do I have to put the statement
B4X:
 Dim glLiveOmzet As LiveOmzet
?
If I put it in the
B4X:
 Sub Globals ...End Sub
then I get the error: Unknown member: glLiveOmzet !
Andif I delete the statement
B4X:
 Dim glLiveOmzet As LiveOmzet
then I get a log list with errors
 
Upvote 0

Rotterdamse Adje

Member
Licensed User
Longtime User
Yes, see following code:
B4X:
Sub Class_Globals
#Region 'oude dims
'    Dim Password As String
'    Dim datum As String 'de laatste datum
'    Dim tijd As String 'de laatste tijd
'    Dim OmzDames As Double
'    Dim OmzHeren As Double
'    Dim KortEnServ As Double 
'    Dim aantalAfrekeningen As Int 'aantal afrekeningen van vandaag
'    Dim FTPCompleted As Boolean 
'    Dim FTPSucces  As Boolean
#End Region
    Dim SamRTOmzetlines As List
    Private Activity As Activity
End Sub
Additional, I've added the source code of the class module
 

Attachments

  • LiveOmzet.bas.zip
    1.6 KB · Views: 118
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It has nothing to do with the new version.
If a class has a global variable that needs an activity context, such as views or Activity, then it cannot be declared in Process_Globals. The best solution, of course, is to switch to B4XPages and forget from all of these nuances.

You can declare the class instance in Globals instead of Process_Globals.
 
Upvote 0
Top