У меня есть класс с именем 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 сообщает, что создаст его, если он не существует
Что может быть не так?