Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot cast from ArrayList<Parcelable> to ArrayList<ClSprite>

Tags:

java

casting

In a piece of code I've written, I have this line:

         AllSprites = (ArrayList<ClSprite>) savedInstanceState.getParcelableArrayList("AllSprites");

I'm getting an error about an invalid cast from an ArrayList<Parcelable> to ArrayList<ClSprite>. Why isn't this legal?

like image 543
Steven Marcus Avatar asked Aug 05 '11 04:08

Steven Marcus


1 Answers

A simple solution is to set the returning element type like so

ArrayList<ClSprite> AllSprites = savedInstanceState.<ClSprite>getParcelableArrayList("AllSprites")

like image 144
Ralph H.M. Avatar answered Oct 19 '22 14:10

Ralph H.M.