Android Question trouble with writeb4xobject

techknight

Well-Known Member
Licensed User
Longtime User
I am having a weird issue with the Writeb4xobject function telling me the map isnt initialized when it is...

Here is my subroutine:
B4X:
Sub WriteConfig
    Dim R As RandomAccessFile
    Dim AppSettings As Map
    R.Initialize(File.DirInternal, "settingsv2.ini", False)
    AppSettings.Initialize
    AppSettings.Put("ConfigVersion", ConfigVersion)
    AppSettings.Put("Brightnessval", CommEngine.Brightnessval)
    AppSettings.Put("TeamName", ScoreEngine.TeamName)
    AppSettings.Put("GameOptions", ScoreEngine.GameOptions)
    AppSettings.Put("GameData", ScoreEngine.GameData)
    AppSettings.Put("Baseball", ScoreEngine.Baseball)
    AppSettings.Put("Soccer", ScoreEngine.Soccer)
    AppSettings.Put("GameClock", ScoreEngine.GameClock)
    Log(AppSettings.IsInitialized)
    R.WriteB4XObject(AppSettings, 0)
    R.Close
End Sub

A screenshot which shows the line numbers.
1649275262571.png


Here is my error log:
B4X:
true
Error occurred on line: 142 (Common)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:224)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.WriteB4XObject(RandomAccessFile.java:326)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265)
    at md.vscbmultisport.common._writeconfig(common.java:296)
    at md.vscbmultisport.main._activity_keypress(main.java:767)
    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 md.vscbmultisport.main$HandleKeyDelayed.runDirectly(main.java:231)
    at md.vscbmultisport.main$HandleKeyDelayed.run(main.java:228)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6823)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:159)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283)
    ... 27 more
** Activity (main) Pause, UserClosed = true **

the true is the log telling me the map is initialized, but clearly its not when it tries to write b4xobject

thoughts? Thanks.
 

OliverA

Expert
Licensed User
Longtime User
Are any of the items in ScoreEngine a map by chance? If so, is that map initialized?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Are any of the items in ScoreEngine a map by chance? If so, is that map initialized?

ScoreEngine is a code module, that's where my global variables sit.

What is funny is if i comment out "Baseball" it works. leave baseball uncommented, it doesnt.

I can initialize baseball with ScoreEngine.Baseball.Initialize, and then store it? same problem.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Wait... I think i found the problem. Baseball variable points to a customtype, and inside that custom type i have a couple of Maps.

Im not using those maps yet, and i wonder if thats why....
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Yes. All maps have to be initialized. Even unused ones. Part of initializing your custom type should be the initialization of any lists, maps, objects, etc. contained in it, especially if you want to write the object to a file
 
Upvote 0
Top