I try to save names and ages of people who play the little game that I develop.
I defined a type INI (see Process_Globals below) and defined INIval as a variable for 1 person and INIvalues as a list for a lot of persons.
In SAVE_Click the List is saved. So far so good, BUT
In LOAD_Click I get an error: ClassCastException:Java.Lang.String cannot be cast
How to avoid this?
TD NL 3843 XP
SOURCE CODE:
Sub Process_Globals
Type INI (FamilyName As String, Age As Int)
End Sub
Sub Globals
Dim INIval As INI
Dim INIvalues As List
Private LOAD As Button 'to retrieve data from file
Private Naam As EditText 'to get the familyname
Private RESULT As Label 'to present the retrieved data
Private SAVE As Button 'to save the list
Private Age As EditText 'to get the age
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") 'you can image what it looks like?
INIval.Initialize()
INIvalues.Initialize()
End Sub
Sub Naam_EnterPressed
INIval.FamilyName = Naam.Text
End Sub
Sub Age_EnterPressed
INIval.Age = Age.text
End Sub
Sub SAVE_Click
INIvalues.Add(INIval)
File.WriteList(File.DirRootexternal, "TEST.ini", INIvalues)
End Sub
Sub LOAD_Click
INIvalues = File.ReadList(File.DirRootexternal, "TEST.ini")
INIval = INIvalues.Get(0)
RESULT.Text = INIval.FamilyName & " " & INIval.Age
End Sub
I defined a type INI (see Process_Globals below) and defined INIval as a variable for 1 person and INIvalues as a list for a lot of persons.
In SAVE_Click the List is saved. So far so good, BUT
In LOAD_Click I get an error: ClassCastException:Java.Lang.String cannot be cast
How to avoid this?
TD NL 3843 XP
SOURCE CODE:
Sub Process_Globals
Type INI (FamilyName As String, Age As Int)
End Sub
Sub Globals
Dim INIval As INI
Dim INIvalues As List
Private LOAD As Button 'to retrieve data from file
Private Naam As EditText 'to get the familyname
Private RESULT As Label 'to present the retrieved data
Private SAVE As Button 'to save the list
Private Age As EditText 'to get the age
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") 'you can image what it looks like?
INIval.Initialize()
INIvalues.Initialize()
End Sub
Sub Naam_EnterPressed
INIval.FamilyName = Naam.Text
End Sub
Sub Age_EnterPressed
INIval.Age = Age.text
End Sub
Sub SAVE_Click
INIvalues.Add(INIval)
File.WriteList(File.DirRootexternal, "TEST.ini", INIvalues)
End Sub
Sub LOAD_Click
INIvalues = File.ReadList(File.DirRootexternal, "TEST.ini")
INIval = INIvalues.Get(0)
RESULT.Text = INIval.FamilyName & " " & INIval.Age
End Sub