I'm quite new to Android and I've recently started a new project that has to deal with files (to store vital flexible data that would be read each time the app starts). I've looked at some ways to write/read files at Stackoverflow (for example, this or this), at Android Devs official website and so on. I've tried all of them and every time I tried a new way, my app just crashed (even when there's just a function that deals with files, which is even never called in the code). The first error thrown in Android Monitor is always as follows:
E/System: stat file error, path is /data/app/com.example.android.a6_jars-2/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory)
I tried googling this error, but no solution I've found (in the stackoverflow too) even looked like it would be best for my situation.
Any ideas on how to solve it?
If it helps. here's all of my logcat for that app:
07-29 00:32:32.518 23458-23458/? W/Zygote: mz_is_rooted false
07-29 00:32:32.521 23458-23458/? I/art: Late-enabling -Xcheck:jni
07-29 00:32:32.751 23458-23458/com.example.android.a6_jars E/System: stat file error, path is /data/app/com.example.android.a6_jars-2/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory)
07-29 00:32:32.753 23458-23458/com.example.android.a6_jars W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6ffffffe arg 0x808
07-29 00:32:32.753 23458-23458/com.example.android.a6_jars W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6fffffff arg 0x2
07-29 00:32:32.757 23458-23458/com.example.android.a6_jars I/InstantRun: starting instant run server: is main process
07-29 00:32:32.886 23458-23458/com.example.android.a6_jars E/ActivityThread: Exception when newActivity r=ActivityRecord{2f4ff0b5 token=android.os.BinderProxy@215ed34a {com.example.android.a6_jars/com.example.android.a6_jars.MainActivity}} token=android.os.BinderProxy@215ed34a
07-29 00:32:32.887 23458-23458/com.example.android.a6_jars E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.a6_jars, PID: 23458
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.a6_jars/com.example.android.a6_jars.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2573)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.access$900(ActivityThread.java:183)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:116)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.example.android.a6_jars.MainActivity.<init>(MainActivity.java:22)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1650)
at android.app.Instrumentation.newActivity(Instrumentation.java:1074)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2550)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.access$900(ActivityThread.java:183)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
The code that makes troubles (without it app works normal):
2 functions (one of them is not even called, and even if neither of them is called, the log above looks the same):
public void writeToFile(String data,Context context) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("config.txt", Context.MODE_PRIVATE));
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
public String readFromFile(Context context) {
String ret = "";
try {
InputStream inputStream = context.openFileInput("config.txt");
if ( inputStream != null ) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String receiveString = "";
StringBuilder stringBuilder = new StringBuilder();
while ( (receiveString = bufferedReader.readLine()) != null ) {
stringBuilder.append(receiveString);
}
inputStream.close();
ret = stringBuilder.toString();
}
}
catch (FileNotFoundException e) {
Log.e("login activity", "File not found: " + e.toString());
} catch (IOException e) {
Log.e("login activity", "Can not read file: " + e.toString());
}
return ret;
}
UPD
After dealing with part of code that called findViewById() before the call to setContentView() I still have problems, the logcat is as follows:
07-29 01:22:50.367 27839-27839/? W/Zygote: mz_is_rooted false
07-29 01:22:50.370 27839-27839/? I/art: Late-enabling -Xcheck:jni
07-29 01:22:50.575 27839-27839/com.example.android.a6_jars E/System: stat file error, path is /data/app/com.example.android.a6_jars-1/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory)
07-29 01:22:50.577 27839-27839/com.example.android.a6_jars W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6ffffffe arg 0x808
07-29 01:22:50.577 27839-27839/com.example.android.a6_jars W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6fffffff arg 0x2
07-29 01:22:50.599 27839-27839/com.example.android.a6_jars I/InstantRun: starting instant run server: is main process
07-29 01:22:50.740 27839-27839/com.example.android.a6_jars W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-29 01:22:51.085 27839-27993/com.example.android.a6_jars E/GED: Failed to get GED Log Buf, err(0)
[ 07-29 01:22:51.085 27839:27993 I/ ]
elapse(include ctx switch):6591 (ms), eglInitialize
07-29 01:22:51.085 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: Initialized EGL, version 1.4
07-29 01:22:51.104 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: Get enable program binary service property (1)
07-29 01:22:51.104 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: Initializing program atlas...
07-29 01:22:51.105 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: Program binary detail: Binary length is 169916, program map length is 152.
07-29 01:22:51.105 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 54, and path is /dev/ashmem.
07-29 01:22:51.105 27839-27993/com.example.android.a6_jars I/OpenGLRenderer: No need to use file discriptor anymore, close fd(54).
07-29 01:22:51.130 27839-27839/com.example.android.a6_jars 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