I am trying to save my settings in a file, but always when it comes to writing into the file, I get NullPointerException
02-05 09:54:21.021 4102-4102/? I/art: Not late-enabling -Xcheck:jni (already on)
02-05 09:54:21.092 4102-4102/com.example.andy.newshit W/System: ClassLoader referenced unknown path: /data/app/com.example.andy.newshit-1/lib/x86_64
02-05 09:54:22.588 4102-4180/com.example.andy.newshit D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-05 09:54:22.618 4102-4180/com.example.andy.newshit I/OpenGLRenderer: Initialized EGL, version 1.4
02-05 09:54:22.630 4102-4180/com.example.andy.newshit W/EGL_emulation: eglSurfaceAttrib not implemented
02-05 09:54:22.630 4102-4180/com.example.andy.newshit W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f76333968c0, error=EGL_SUCCESS
02-05 09:54:26.746 4102-4102/com.example.andy.newshit W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
02-05 09:54:26.795 4102-4180/com.example.andy.newshit W/EGL_emulation: eglSurfaceAttrib not implemented
02-05 09:54:26.795 4102-4180/com.example.andy.newshit W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f7633396c80, error=EGL_SUCCESS
02-05 09:54:28.031 4102-4180/com.example.andy.newshit W/EGL_emulation: eglSurfaceAttrib not implemented
02-05 09:54:28.031 4102-4180/com.example.andy.newshit W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f7626d5a640, error=EGL_SUCCESS
02-05 09:54:28.142 4102-4180/com.example.andy.newshit E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7637d5a780
02-05 09:54:28.145 4102-4180/com.example.andy.newshit E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7637d59e50
02-05 09:54:28.146 4102-4180/com.example.andy.newshit D/OpenGLRenderer: endAllStagingAnimators on 0x7f7626dba000 (ListPopupWindow$DropDownListView) with handle 0x7f7626edad00
02-05 09:54:32.604 4102-4102/com.example.andy.newshit D/AndroidRuntime: Shutting down VM
02-05 09:54:32.604 4102-4102/com.example.andy.newshit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.andy.newshit, PID: 4102 java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileOutputStream android.content.Context.openFileOutput(java.lang.String, int)' on a null object reference
at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:183)
at com.example.andy.newshit.Filehandling.writeFile(Filehandling.java:20)
at com.example.andy.newshit.IPandPort.setIP(IPandPort.java:45)
at com.example.andy.newshit.SettingsActivity$1.onClick(SettingsActivity.java:29)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
This is my Class which I have to handle the files
package com.example.andy.newshit;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* Created by buddy on 05.02.16.
*/
public class Filehandling extends AppCompatActivity{
public void writeFile(String Filename, String Text) throws IOException {
FileOutputStream fos = openFileOutput(Filename, Context.MODE_PRIVATE);
fos.write(Text.getBytes());
fos.close();
}
public void readFile(String File) throws IOException {
try {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(openFileInput(File)));
String inputString;
StringBuffer stringBuffer = new StringBuffer();
inputString = inputReader.readLine();
}
catch (IOException e){
e.printStackTrace();
}
}
}
I really hope I can get some help.