Android Question Object should first be initialized (List).

samannnn

Member
i use a list in my activity. sometimes i have this error in Firebase .when i compile my app it words correctly without any crash and can't see this error when i test my app

B4X:
Fatal Exception: java.lang.RuntimeException: Object should first be initialized (List).
       at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
       at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
       at..............game._globals(game.java:1161)
       at java.lang.reflect.Method.invoke(Method.java)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
       at ...............game.initializeGlobals(game.java:327)
       at ...............game.afterFirstLayout(game.java:102)
       at ...............game.access$000(game.java:17)
       at ...............game$WaitForLayout.run(game.java:83)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8506)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

i use a list in main activity:
B4X:
Dim gamelst As List

and use it in game activity:
B4X:
lststrings=Main.gamelst
LogColor("lststrings size : "&lststrings.size,Colors.Blue)

i think this error happen when avtivity is paused long time and user come back to game again. when i see firebase logs i see this:


could anyone tell me why this error happen?
 

Attachments

  • Untitled.png
    Untitled.png
    15.6 KB · Views: 116

Erel

B4X founder
Staff member
Licensed User
Longtime User
could anyone tell me why this error happen?
Because you are wasting your time with the complex activities life cycle. Switch to B4XPages and forget from all such issues.
That's the correct answer.

If this is a very large project and you are not ready to migrate then the answer is that you cannot assume that the main activity is the first activity to start. All public globals should be initialized in the starter service (in non-B4XPages project).
 
Upvote 0

samannnn

Member
Because you are wasting your time with the complex activities life cycle. Switch to B4XPages and forget from all such issues.
That's the correct answer.

If this is a very large project and you are not ready to migrate then the answer is that you cannot assume that the main activity is the first activity to start. All public globals should be initialized in the starter service (in non-B4XPages project).
thank you for your answer.
i try to migrate to b4xpage but now google warn me for a privacy policy and at this time, i have 30 days to change all my apps.

when an app is starting, at the first, main activity run. if we add a variable in public global, it remain in memory and we can use in another activity.
some questions:
why main activity isn't first activity?
android Os destroys main activity if not used?
According to your explanation, if I define list variable in public global in game activity, my problem will be solved?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
why main activity isn't first activity?
If the app was killed in the background, while the main activity was not visible then it might start from a different activity.
This is the main reason for adding the Starter service feature (before B4XPages were introduced).
android Os destroys main activity if not used?
No. The OS will never kill a specific activity.
 
Upvote 0
Top