HashMap myMap = (HashMap) getLastNonConfigurationInstance();
myMap is always null. getLastNonConfigurationInstance() returns an object. My map has two keys “symbol” and “name”.
public Object onRetainNonConfigurationInstance()
{
HashMap myMap = new HashMap();
myMap.put("symbol", this.symbol);
final Object data = myMap;
return data;
}
If
getLastNonConfigurationInstance()returns a non-null object, then(HashMap) getLastNonConfigurationInstance()will either return the same object (if that object is aHashMap), or throw aClassCastException.The situation that you describe is not possible, not unless you’ve uncovered a long-hidden bug in Java’s cast operator. Hint: you haven’t.
Verify that
getLastNonConfigurationInstance()is actually returning a non-null object. Verify thatmyMapis actually null. If you’re using a debugger to check those values, try printing them to the console instead. Debuggers can lie to you sometimes, or at least mislead.