I have images in my assets folder which get called to my main activity when I select them in my recycler view activity.I also have a notification action to call back the main activity when needed (to access settings). However, when I call back the main activity by clicking on the notification action button, I get a nullpointer exception before the main activity shows. I have tried serializing my object so that it gets saved and therefore the nullpointer exception would go away, but it remains.
Here is my code:
item = getIntent().getExtras().getParcelable(ITEM_KEY);
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(item);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
if (item == null) {
pItem = getIntent().getExtras().getParcelable(CustomAdapter.ITEM_KEY_2);
if (pItem == null) {
// throw new AssertionError("Null data item received!");
try {
ObjectInputStream is = new ObjectInputStream(new FileInputStream(fileName));
try {
Object object = is.readObject();
is.close();
if (object != null) {
object = item;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Here is the exception: "Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Parcelable android.os.Bundle.getParcelable(java.lang.String)' on a null object reference"
It applies to "os.writeObject(item);"
I would be grateful for some pointers. Thanks!