ClassCastException: java.lang.string cannot be cast to Object
in
Programming Questions
•
2 years ago
Hi,
The following code:
So I changed it to:
Can anyone explain these errors and possible alternatives to me? From looking up the last error online it seems I can't cast a string variable to a class variable... but then how does it work in the simple treemap example in Ben Frys book "Visualizing Data"?
Would really appreciate any help as I'm still learning :) thanks in advance :D
The following code:
- void addRank(String title){
ranks.add(title);
TitleItem item = (TitleItem) ranks.get(title); - }
So I changed it to:
- void addRank(String title){
int arraySize = ranks.size();
ranks.add(title);
TitleItem item = (TitleItem) ranks.get(arraySize);//gets most recent entry to ArrayList
}
Can anyone explain these errors and possible alternatives to me? From looking up the last error online it seems I can't cast a string variable to a class variable... but then how does it work in the simple treemap example in Ben Frys book "Visualizing Data"?
Would really appreciate any help as I'm still learning :) thanks in advance :D
1