I know this was discussed in the past, and I may have brought it up in the past but sadly its lost in conversation and I cannot find it.
But I am struggling trying to figure out a way to store object arrays of custom types into a WriteB4XObject function.
I tried B4XSerializator but it still didnt work, keeps crashing.
Here is the declaration:
Snippet of the test subroutine:
my "write" routine:
Trouble is, I keep getting crashes such as:
line 924 is the actual End Sub statement, so the line number its providing is somehow invalid.
Prior to using serializator, I was trying to store the array directly into the Map, but it failed with similar crashes, it would also cause the array to be null and would no longer work right and crash elsewhere.
I am sure there is a way to fix it, but it escapes me at the moment
thanks
But I am struggling trying to figure out a way to store object arrays of custom types into a WriteB4XObject function.
I tried B4XSerializator but it still didnt work, keeps crashing.
Here is the declaration:
B4X:
Type GameClockData (Deciseconds As Int, MaxDeciSeconds As Int, ClockSet As Boolean, ClockStopped As Boolean, ClockDirection As Int)
Public PenaltyClock(2) As GameClockData
Snippet of the test subroutine:
B4X:
Try
If AppSettings.ContainsKey("PenaltyClock") = True Then
Dim Serializer As B4XSerializator
Log(AppSettings.Get("PenaltyClock"))
ScoreEngine.PenaltyClock = Serializer.ConvertBytesToObject(AppSettings.Get("PenaltyClock"))
Else
For I = 0 To ScoreEngine.PenaltyClock.Length-1
ScoreEngine.PenaltyClock(I).Initialize
ScoreEngine.PenaltyClock(I).ClockStopped = True
ScoreEngine.PenaltyClock(I).ClockSet = False
ScoreEngine.PenaltyClock(I).Deciseconds = 0
ScoreEngine.PenaltyClock(I).ClockDirection = 0
Next
End If
Catch
For I = 0 To ScoreEngine.PenaltyClock.Length-1
ScoreEngine.PenaltyClock(I).Initialize
ScoreEngine.PenaltyClock(I).ClockStopped = True
ScoreEngine.PenaltyClock(I).ClockSet = False
ScoreEngine.PenaltyClock(I).Deciseconds = 0
ScoreEngine.PenaltyClock(I).ClockDirection = 0
Next
End Try
my "write" routine:
B4X:
Sub WriteConfig
Dim R As RandomAccessFile
Dim AppSettings As Map
Dim Serializer As B4XSerializator
R.Initialize(File.DirInternal, "settingsv2.ini", False)
AppSettings.Initialize
AppSettings.Put("ConfigVersion", ConfigVersion)
AppSettings.Put("ConnectionProperties", CommEngine.ConnectionProperties)
AppSettings.Put("Brightnessval", CommEngine.Brightnessval)
AppSettings.Put("TeamName", ScoreEngine.TeamName)
AppSettings.Put("GameOptions", ScoreEngine.GameOptions)
AppSettings.Put("Paintball", ScoreEngine.Paintball)
AppSettings.Put("GameClock", ScoreEngine.GameClock)
AppSettings.Put("BreakClock", ScoreEngine.BreakClock)
AppSettings.Put("PenaltyClock", Serializer.ConvertObjectToBytes(ScoreEngine.PenaltyClock))
R.WriteB4XObject(AppSettings, 0)
R.Close
End Sub
Trouble is, I keep getting crashes such as:
B4X:
Error occurred on line: 924 (Main)
java.lang.IllegalArgumentException: field md.smpaintball1b.scoreengine._penaltyclock has type md.smpaintball1b.scoreengine$_gameclockdata[], got java.lang.Object[]
at java.lang.reflect.Field.set(Native Method)
at anywheresoftware.b4a.shell.Shell.setStateBeforeUserSub(Shell.java:509)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:411)
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.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at md.smpaintball1b.main._readconfig(main.java:689)
at md.smpaintball1b.main._activity_create(main.java:582)
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.smpaintball1b.main.afterFirstLayout(main.java:105)
at md.smpaintball1b.main.access$000(main.java:17)
at md.smpaintball1b.main$WaitForLayout.run(main.java:83)
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)
** Activity (main) Resume **
line 924 is the actual End Sub statement, so the line number its providing is somehow invalid.
Prior to using serializator, I was trying to store the array directly into the Map, but it failed with similar crashes, it would also cause the array to be null and would no longer work right and crash elsewhere.
I am sure there is a way to fix it, but it escapes me at the moment
thanks