Android Question Type variable in list/file crash

techknight

Well-Known Member
Licensed User
Longtime User
So, I have a type and list of this:

B4X:
Type PlayerInfo (Number As String, Name As String, Points As Int, Fouls As Int, OnCourt As Boolean, Slot As Int)
Dim HomeRoster As List

HomeRoster is Initialized during the app launch, So lets say that I do this:
B4X:
Dim PI as PlayerInfo
PI.Initialize

PI.Name = "TestPlayer"
PI.Number = "12" 'I use a string here because you have a player jersey of 00.
HomeRoster.Add(PI)

Notice I didnt set the fouls or points as they arnt necessary at this point.

So then I save the list into a file, Like this:
B4X:
File.WriteList(File.DirInternal, "/rosterv2/" & side & "/" & filename, HomeRoster)

Then later on, I recall the file with this subroutine:
B4X:
Sub LoadRoster(filename As String, side As String)
    Dim PI As PlayerInfo
    PI.Initialize
    Dim I As Int
    If side = "home" Then 
        HomeRoster = File.ReadList(File.DirInternal, "/rosterv2/" & side & "/" & filename)
        For I = 0 To HomeRoster.Size - 1 'Remove Player points, Fouls, and On Court status.
            PI = HomeRoster.Get(I)
            Log(PI)
            PI.Fouls = 0
            PI.Points = 0
            PI.OnCourt = False
            HomeRoster.Set(I, PI)
        Next
    Else
        GuestRoster = File.ReadList(File.DirInternal, "/rosterv2/" & side & "/" & filename)
        For I = 0 To GuestRoster.Size - 1 'Remove Player points, Fouls, and On Court status.
            PI = GuestRoster.Get(I)
            PI.Fouls = 0
            PI.Points = 0
            PI.OnCourt = False
            GuestRoster.Set(I, PI)
        Next
    End If
    LoadPlayers
End Sub

But here is the problem. It crashes on PI.Fouls = 0 point with this:

B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (servicemain) Create ***
** Service (servicemain) Start **
releasing KeepAlive
No wakelock.
turning screen on
using partialLock
*** Service (servicetxrx) Create ***
** Service (servicetxrx) Start **
---- AppUpdating.ReadCurVN
UpdateComplete - time: 10:26:57
---- AppUpdating.ReadWebVN
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
---- AppUpdating.JobDone --
UpdateComplete - time: 10:26:57
[Number=31, Name=SIX, IsInitialized=true
Error occurred on line: 1394 (Main)
java.lang.RuntimeException: Field: Fouls not found in: java.lang.String
    at anywheresoftware.b4a.shell.Shell$FieldCache.getField(Shell.java:908)
    at anywheresoftware.b4a.shell.Shell.setField(Shell.java:655)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog$2.onClick(InputDialog.java:2079)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5602)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Error occurred on line: 1394 (Main)
java.lang.RuntimeException: Unexpected command: 0
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:417)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog$2.onClick(InputDialog.java:2079)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5602)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.OutOfMemoryError: java.lang.Object[] of length 1963329536 exceeds the VM limit
    at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:220)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:366)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog$2.onClick(InputDialog.java:2079)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5602)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

This is where I am stuck.
 

techknight

Well-Known Member
Licensed User
Longtime User
So his tutorial I cant find where he covers List.IndexOf.

So I tried it and it fails of course.

So how do I use IndexOf with my custom type?
 
Upvote 0
Top