0

I need to pass to a secondary activity an object defined as:

public class Campionati extends ArrayList<Campionato> implements Serializable {

I'm able to create an extra containing the object. In the onCreate() function of the secondary activity I go to retrieve the data by the code:

 Bundle b = getIntent().getExtras();
 if (b!=null) {
        Serializable s = b.getSerializable("datiSport");
        Campionati m_campionati = (Campionati)s;

Both b and s objects are good and s is typed as ArrayList. The last command generates an exception:

Java.lang.ClassCastException: Java.util.ArrayList

What does it mean? I don't understand why the cast is not possible .

1 Answer 1

4

What does it mean? I don't understand why the cast is not possible .

It means that the object in question is an ArrayList of some kind, not a Campionati.

Your inheritance relationship means that any Campionati can be treated as an ArrayList - but the reverse is not true. You can only cast to Campionati if the object in question is actually an instance of Campionati or a subclass.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.