我收到 FATAL Exception 主要错误。有什么帮助吗?
这是代码:
私人无效复制流(字符串资产文件名,字符串 outFileName)抛出 IOException {
Process mSuProcess; mSuProcess = Runtime.getRuntime().exec("su"); ContextWrapper myContext = null; InputStream myInput = myContext.getAssets().open(assetFilename); OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[2048]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void copyon(View view) throws IOException { copyStream("floaton.xml","/system/etc/excluded-input-devices.xml"); } public void copyoff(View view) throws IOException { copyStream("floatoff.xml","/system/etc/excluded-input-devices.xml"); }
和logcat
09-16 19:52:26.654: E/AndroidRuntime(294):FATAL EXCEPTION: main 09-16 19:52:26.654: E/AndroidRuntime(294):java.lang.IllegalStateException: 无法执行活动的方法09-16 19:52:26.654: E/AndroidRuntime(294):at android.view.View$1.onClick(View.java:2144) 09-16 19:52:26.654: E/AndroidRuntime(294):at android .view.View.performClick(View.java:2485) 09-16 19:52:26.654: E/AndroidRuntime(294):at android.view.View$PerformClick.run(View.java:9080) 09-16 19 :52:26.654: E/AndroidRuntime(294):at android.os.Handler.handleCallback(Handler.java:587) 09-16 19:52:26.654: E/AndroidRuntime(294):at android.os.Handler。 dispatchMessage(Handler.java:92) 09-16 19:52:26.654: E/AndroidRuntime(294):at android.os.Looper.loop(Looper.java:123) 09-16 19:52:26.654: E/ AndroidRuntime(294):at android.app.ActivityThread.main(ActivityThread.java:3683) 09-16 19:52:26.654: E/AndroidRuntime(294):at java.lang.reflect.Method.invokeNative(Native Method) 09-16 19:52:26.654: E/AndroidRuntime(294):at java.lang.reflec t.Method.invoke(Method.java:507) 09-16 19:52:26.654: E/AndroidRuntime(294):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 09 -16 19:52:26.654: E/AndroidRuntime(294):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 09-16 19:52:26.654: E/AndroidRuntime(294):在 dalvik.system.NativeStart.main(Native Method) 09-16 19:52:26.654: E/AndroidRuntime(294):Caused by: java.lang.reflect.InvocationTargetException 09-16 19:52:26.654: E/AndroidRuntime (294):at java.lang.reflect.Method.invokeNative(Native Method) 09-16 19:52:26.654: E/AndroidRuntime(294):at java.lang.reflect.Method.invoke(Method.java:507 ) 09-16 19:52:26.654: E/AndroidRuntime(294):at android.view.View$1.onClick(View.java:2139) 09-16 19:52:26.654: E/AndroidRuntime(294):. .. 11 更多 09-16 19:52:26.654: E/AndroidRuntime(294): 由: java.io.IOException: Broken pipe 09-16 19:52:26.654: E/AndroidRuntime(294): at org. apache.harmony.luni.platform.OSFileSystem.write(Native Method) 09-16 19:52: 26.654: E/AndroidRuntime(294): 在 dalvik.system.BlockGuard$WrappedFileSystem.write(BlockGuard.java:171) 09-16 19:52:26.654: E/AndroidRuntime(294): 在 java.io.FileOutputStream.write (FileOutputStream.java:300) 09-16 19:52:26.654: E/AndroidRuntime(294):at java.io.FileOutputStream.write(FileOutputStream.java:256) 09-16 19:52:26.654: E/AndroidRuntime (294):在 java.io.DataOutputStream.writeBytes(DataOutputStream.java:167)
异常的基础似乎来自“FileOutputStream.write”,您是否将写入权限添加到您的清单?