1
try {
    fis = context.openFileInput("Stores");
    ObjectInputStream oi = new ObjectInputStream(fis);
    toReturn = (ArrayList<Store>) oi.readObject();
    oi.close();
} catch (FileNotFoundException e) {
    Log.e("InternalStorage", e.getMessage());
} catch (IOException e) {
    Log.e("InternalStorage", e.getMessage());
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

I have a crashlog on the IOException scope, saying

java.lang.NullPointerException: println needs a message

Why would this happen?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
quantumpotato
  • 9,637
  • 14
  • 70
  • 146

1 Answers1

1

Because IOException always returns null when you call e.getMessage(). Try to log something else when this exception occurs.

For example:

    StackTraceElement[] stackTraceElements = e2.getStackTrace();
    String logMessage = "IOException occured in method "
            + stackTraceElements[0].getMethodName() + " - File name is "
            + stackTraceElements[0].getFileName()
            + " - At line number: "
            + stackTraceElements[0].getLineNumber();
    Log.e("InternalStorage", e.getMessage());