0

Can someone explain why this code doesn't work?

Intent i = new Intent(this.context, SomeClass.class);
HashMap<String, String> tmp1 = new HashMap<String, String>();
Log.d(TAG, "IN: " + String.valueOf(tmp1));
i.putExtra("VAR", tmp1);
HashMap<String, String> tmp2 = i.getParcelableExtra("VAR");
Log.d(TAG, "OUT: " + String.valueOf(tmp2));

What I expect to get:

  • HashMap is parcellable. tmp1 should equal tmp2.

What I actually get (LogCat):

  • Debug: IN: {}
  • Warning: Key VAR expected Parcelable but value was a java.util.HashMap. The default value <null> was returned.
  • Warning: Attempt to cast generated internal exception: java.lang.ClassCastException: java.util.HashMap
  • Debug: OUT: null

1 Answer 1

3

I think you are mistaken, HashMap is not Parcelable. It is however Serializable, so you are putting a Serializable extra and trying to read it as a Parcelable, which causes the error.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.