problem: an item in a list of custom type is being treated as type string
attached please find a snippet which reproduces the error
i have a list of (custom) type FAV which the user can select and add new entries to.
when the app launches, it tries to read in any previously saved list.
if there is no list (or no file containing the list), it creates a first entry for the list and writes the list to a file. so, if no additions are made to the list, the next time the user runs the app, there should be a single entry in the list, right?
this is the error when the user launches app and tries to access items in the list:
java.lang.ClassCastException: java.lang.String cannot be cast to b4a.example.main$_fav
so i go, wait - what string? i put together this snippet to duplicate the error.
1) to be safe, delete the saved list if it exists. if you're compiling for the first time, you can comment that out.
2) there is no initial list (or file), create the first entry, add it to the (empty) list, and save the list to disk.
3) app "confirms" that the list contains 1 entry. presumably it wrote 1 entry to disk...
4) exit
1) comment out line that deletes file
2) run app
3) since we know we saved 1 entry last time, read the list from disk
4) crash.
after creating and saving the first (and only) entry, i added a log comment to see what the app thought it was loading: 2 entries! so then i added a line of code and a couple log comments to see how many entries the app thought it was reading in right after it finished writing 1 entry. again 2.
i often use lists of custom types and assign the output from list.get() to an object of my type. i've never seen this error before. what am i missing here? i assume some blood from head banging has gotten into my eyes; i'm just not seeing it. tks.
-go
attached please find a snippet which reproduces the error
i have a list of (custom) type FAV which the user can select and add new entries to.
when the app launches, it tries to read in any previously saved list.
if there is no list (or no file containing the list), it creates a first entry for the list and writes the list to a file. so, if no additions are made to the list, the next time the user runs the app, there should be a single entry in the list, right?
this is the error when the user launches app and tries to access items in the list:
java.lang.ClassCastException: java.lang.String cannot be cast to b4a.example.main$_fav
so i go, wait - what string? i put together this snippet to duplicate the error.
1) to be safe, delete the saved list if it exists. if you're compiling for the first time, you can comment that out.
2) there is no initial list (or file), create the first entry, add it to the (empty) list, and save the list to disk.
3) app "confirms" that the list contains 1 entry. presumably it wrote 1 entry to disk...
4) exit
1) comment out line that deletes file
2) run app
3) since we know we saved 1 entry last time, read the list from disk
4) crash.
after creating and saving the first (and only) entry, i added a log comment to see what the app thought it was loading: 2 entries! so then i added a line of code and a couple log comments to see how many entries the app thought it was reading in right after it finished writing 1 entry. again 2.
i often use lists of custom types and assign the output from list.get() to an object of my type. i've never seen this error before. what am i missing here? i assume some blood from head banging has gotten into my eyes; i'm just not seeing it. tks.
-go