Android Question Abnormal Error while execution

AndroidMadhu

Active Member
Licensed User
Hello,
While trying to run the code in b4xpages I am facing the below error as follows :
B4X:
Activity (main) Resume **
Error occurred on line: 56 (B4XMainPage)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (Button).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:311)
at b4a.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:198)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
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 anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1704)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)

The below is the code base :
B4X:
 Private Sub B4XPage_Created (Root1 As B4XView)
Log("create")
If Not(rp.Check(rp.PERMISSION_ACCESS_FINE_LOCATION)) Then
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
End If
Root = Root1
Root.LoadLayout("splash2")
ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "welcome.png", ImageView1.Width, ImageView1.Height, True))
Sleep(1000)


cImei=GenerateID
If File.Exists(File.DirInternal, "Test.db") = False Then
SQL1.Initialize(File.DirInternal, "Test.db", True)
CreateDataBase
Else
SQL1.Initialize(File.DirInternal, "Test.db", True)
End If

cur= SQL1.ExecQuery("select * from test")

If cur.RowCount==0 Then
Root.LoadLayout("reg1")   ===> getting error at this line

Else
cur.Position=0
cName=cur.GetString("name")
cPhone=cur.GetString("phone")
Root.LoadLayout("MainPage")
Wait For MapFragment1_Ready
gmap = MapFragment1.GetMap
gmap.GetUiSettings.ZoomControlsEnabled=False

gmap.MyLocationEnabled = True
gmap.TrafficEnabled=False

Do While gmap.MyLocation.IsInitialized = False
'Log("Location not initialized... Sleep a while...")
Sleep(250)
Loop

If gmap.MyLocation.IsInitialized Then
Dim CameraPosition1 As CameraPosition
gmap.MapType=gmap.MAP_TYPE_NORMAL
gmap.MyLocationEnabled = True
CameraPosition1.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude, 16)
gmap.MoveCamera(CameraPosition1)
End If

End If
cur.Close

End Sub

Please advice
 

Mahares

Expert
Licensed User
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
The first thing that sticks out is the above line should be:
B4X:
Wait For B4Xpage_PermissionResult (Permission As String, Result As Boolean)
. I have not checked the rest of the code.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Wait For B4Xpage_PermissionResult (Permission As String, Result As Boolean)
I have change the code as mentioned.
But still I am getting the error.
When I change the code as below it is running fine...
B4X:
Root.LoadLayout("mainpage")

But if I keep the code as below I am getting error
B4X:
Root.LoadLayout("reg1")

Please advice
 
Upvote 0

Peter Simpson

Expert
Licensed User
Are you still getting an 'Object should first be initialized (Button)' error (you didn't say if it was the same error or a different error), if so what buttons have you got in your reg1 layout? In theory if you have buttons in that layout, you do not need to initialized them as it done automatically.

You could always try cleaning your project, if that does not work as it probably will not then removing the buttons, saving the layout then adding the buttons back again might help you. But I doubt that too...
 
Upvote 0
Top