Android Question Object should first be initialized (B4XView)

BOHANG

Member
My program has multiple pages and is managed through B4XPages. When I use (dd. GetViewByName (p, "Label1") Text="Name") Modify the text prompt java. lang. TimeException: Object should be initialized first (B4XView). I have added DDD.CollectViewsDat in the mini script.

The following patterns occur on pages with errors
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    lab_loading.Left=Root.Width/2-lab_loading.Width/2
    lab_loading.Top=Root.Height/3
    CLASS1.Initialize
    B4XPages.GetManager.TransitionAnimationDuration = 0
    PLAYER_PAGE.Initialize
    B4XPages.AddPageAndCreate("PLAYER", PLAYER_PAGE)
    SETTING_PAGE.Initialize
    B4XPages.AddPageAndCreate("SETTING", SETTING_PAGE)
    GUI_PAGE.Initialize
    B4XPages.AddPageAndCreate("GUI", GUI_PAGE)
    B4XPages.ShowPage("MainPage")
End Sub

When I first initialize PLAYER-PAGE, then initialize SETTING-PAGE. At this point, modifying tag text on the PLAYER-PAGE page will result in an error, while SETTING-PAGE will not. If SETTING-PAGE is initialized first and then PLAYER-PAGE is initialized, the problem will occur on the SETTING-PAGE page
 
Solution
Try to reproduce it in a small project and upload it.
Thank you for your help, the problem has been resolved. The reason is that my program has multiple pages, and each page initializes its own DDD. This is not possible. Change to initialize DDD on the first page and use the DDD from the first page for other pages

BOHANG

Member
Please run in release mode and post the full error message.
error code:
playerpage_createclientlist (java line: 1778)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
    at anywheresoftware.b4a.objects.B4XViewWrapper.setWidth(B4XViewWrapper.java:132)
    at b4a.example.playerpage._createclientlist(playerpage.java:1778)
    at b4a.example.playerpage._initplayerclientlist(playerpage.java:2396)
    at b4a.example.playerpage._btn_settingexit_click(playerpage.java:953)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6675)
    at android.view.View.performClickInternal(View.java:6647)
    at android.view.View.access$3100(View.java:791)
    at android.view.View$PerformClick.run(View.java:26339)
    at android.os.Handler.handleCallback(Handler.java:907)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7779)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:990)
playerpage_createclientlist (java line: 1778)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
    at anywheresoftware.b4a.objects.B4XViewWrapper.setWidth(B4XViewWrapper.java:132)
    at b4a.example.playerpage._createclientlist(playerpage.java:1778)
    at b4a.example.playerpage._initplayerclientlist(playerpage.java:2396)
    at b4a.example.playerpage._btn_settingexit_click(playerpage.java:953)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6675)
    at android.view.View.performClickInternal(View.java:6647)
    at android.view.View.access$3100(View.java:791)
    at android.view.View$PerformClick.run(View.java:26339)
    at android.os.Handler.handleCallback(Handler.java:907)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7779)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:990)

1723528478570.png
 
Upvote 0

BOHANG

Member
There is also a rule that when the program runs for the first time, initializing and executing this code will not result in errors. The error will only occur when called again later.
 
Upvote 0

BOHANG

Member
Try to reproduce it in a small project and upload it.
Thank you for your help, the problem has been resolved. The reason is that my program has multiple pages, and each page initializes its own DDD. This is not possible. Change to initialize DDD on the first page and use the DDD from the first page for other pages
 
Upvote 0
Solution
Top