The app wants to store data about a jump (length, height, time)
Whenever I try to read my file I get this exception in the line "File directory = context.getFilesDir();
"
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference"
I don't really know what to put in the context, so it's not null.
Thanks in advance!
public class Save {
static private String savedData;
private static Context context;
static String stringJump;
public static void Save(Jump jump) {
savedData += jump.getLength() + " ";
savedData += jump.getHeight() + " ";
savedData += jump.getTime() + " ";
FileOutputStream outputStream;
String filename = "savedJump";
try {
outputStream = context.openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(savedData.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
stringJump = read_file(context, filename);
Toast.makeText(context, stringJump, Toast.LENGTH_SHORT).show();
}
public static String read_file(Context context, String filename) {
File directory = context.getFilesDir();
File file = new File(directory, filename);
return file.toString();
}
}