我有一个名为 FileGeneration 的类,它扩展了 Activity
在 FileGeneration 中我有一个名为
protected OutputStream openAndWriteFile() {
// Set the Context-mode
int cxt = Context.MODE_PRIVATE;
// Check if we are not going to clear the file and the file exists
if (!clearFile && (new File(this.fileName)).exists()) {
// Append to the file
cxt = Context.MODE_APPEND;
}
// Try to open the file to write to
try {
// Open the File using the Context
this.os = openFileOutput(this.fileName, cxt);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Return the OutputStream
return this.os;
}
我在 Logcat 中得到这个输出
06-08 15:31:43.733: ERROR/AndroidRuntime(2850): java.lang.NullPointerException
06-08 15:31:43.733: ERROR/AndroidRuntime(2850): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
06-08 15:31:43.733: ERROR/AndroidRuntime(2850): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
06-08 15:31:43.733: ERROR/AndroidRuntime(2850): at dataconnection.FileGeneration.openAndWriteFile(FileGeneration.java:278)
类中的第 278 行是
this.os = openFileOutput(this.fileName, cxt);
但是当我在 Logcat 中打印带有参数的方法时,它会说
openFileOutput(Preferences.xml, 1);
该文件不存在,但 openFileOutput 表示如果不存在,它将创建它
有什么问题吗?
我解决了这个问题(new ContextWrapper(ctx)).openFileOutput(this.fileName, cxt)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)