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();
}
我在IOException范围内有一个崩溃日志,说
java.lang.NullPointerException: println needs a message
为什么会发生这种情况?
答案 0 :(得分:0)
因为在调用e.getMessage()时IOException总是返回null。 发生此异常时,请尝试记录其他内容。
例如:
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());