Your context "c" is null. Seeing that you're calling this method from an activity, pass the context from your activity into your method. Note the Context
parameter in the method declaration
public void saveSth(Context c) {
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = null;
try {
fos = c.openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
Your call to the method from within your activity would be something like:
cacheOperator.saveSth(this);