Could not open stack trace file '/data/anr/traces.txt': permission denied

I am new to the Android world.

I made a request for user registration. It worked fine. but when I tried to add a spinner to my activity file, it showed an error in avd, for example,

Application registration (com.students process) was stopped unexpectedly. try again

is coming.

and my log code shows an error

"11-12 10: 42: 06.816: E / dalvikvm (313): cannot open the stack trace file '/data/anr/traces.txt': Permission denied"

What is this mistake? How can I get rid of this?

+7
source share
4 answers

This was a problem that I encountered when I was new to Android. Then I found out that the message about the impossibility of writing to the traces.txt file is not a real problem with the program.

Thus, the solution to this problem is to find and fix the actual (not related to this message) cause of the program crash. Then this message (which reflects a configuration problem in the crash reporting system) will no longer be.

+3
source

You are trying to access external storage. Make sure you have the required permission defined in your manifest file. This can be done by adding

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+10
source

This error has nothing to do with your application. Its referring stack trace file, which is generated when the application crashes, so that the user can report this to the publisher. The reason you see this error is because your application was not installed on the Android market, so it does not have permission to write to this file. Errors that your application generates during debugging can be seen in LogCat and the stack trace describing the error will be reset there.

+4
source

To work in the file /data/anr/traces.txt you need root or the system user chmod.
ActivityManagerService#dumpStackTraces :

 public static File dumpStackTraces(boolean clearTraces, ArrayList<Integer> firstPids, ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids, String[] nativeProcs) { String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null); if (tracesPath == null || tracesPath.length() == 0) { return null; } File tracesFile = new File(tracesPath); try { if (clearTraces && tracesFile.exists()) tracesFile.delete(); tracesFile.createNewFile(); FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- } catch (IOException e) { Slog.w(TAG, "Unable to prepare ANR traces file: " + tracesPath, e); return null; } dumpStackTraces(tracesPath, firstPids, processCpuTracker, lastPids, nativeProcs); return tracesFile; } 

And I handle the problem in the shell as follows. adb root
adb shell touch /data/anr/traces.txt
adb shell kill -3 ${APP_PID}

+1
source

All Articles