Cannot cure RAF error with Casting

enonod

Well-Known Member
Licensed User
Longtime User
I never seem to get anything right first time.
I am trying to save the Object aGrid as a whole. The file is created but of course I cannot examine the content.
Can anybody please suggest what I am missing when reading back?
The line quoted in the error is *** below and the error...
...
java.lang.ClassCastException:java.lang.String

B4X:
Sub Process_Globals
  Type Steer(C As Byte, R As Byte)
  Type Movers(colour As Byte, dir As Steer, del As Boolean, arrow As Boolean)
  Dim aGrid(18,18) As Movers
...
End Sub

Sub SaveGame
Dim raf As RandomAccessFile
Dim filename As String
   filename=sPlayer&".dat"
   raf.Initialize(File.DirDefaultExternal,filename,False)
   raf.WriteObject("aGrid",True,raf.CurrentPosition)
   raf.close
End Sub

Sub LoadGame
Dim raf As RandomAccessFile
Dim filename As String
   filename=sPlayer&".dat"
   If File.Exists(File.DirDefaultExternal, filename) = True Then
   raf.Initialize(File.DirDefaultExternal,filename,False)
***   aGrid=raf.ReadObject(raf.CurrentPosition)
   raf.close
   End If
End Sub
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you so much for spotting that agraham.
 
Upvote 0
Top