IOException 为获取消息返回 null
IOException returning null for get message
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
为什么会这样?
因为当您调用 e.getMessage() 时,IOException 总是 returns 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());
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
为什么会这样?
因为当您调用 e.getMessage() 时,IOException 总是 returns 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());