我越來越致命異常主要error.Any幫助嗎?致命異常主要android
下面是代碼:
私人無效copyStream(字符串assetFilename,字符串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):致命例外:main 0 9-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/AndroidR (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.reflect.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/AndroidRuntim e(294):at dalvik.system.NativeStart.main(本機方法)09-16 19:52:26.654: E/AndroidRuntime(294):導致: 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。反射。方法.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: 斷開的管道09-16 19 :52:26.654:E/AndroidRuntime(294):at org.apache.harmony.luni.pl atform.OSFileSystem.write(Native Method) 09-16 19:52:26.654:E/AndroidRuntime(294):at dalvik.system.BlockGuard $ WrappedFileSystem.write(BlockGuard.java:171) 09-16 19: E:/ AndroidRuntime(294):at java.io.FileOutputStream.write(FileOutputStream.java:300)09-16 19:52:26.654: FileOutputStream.write(FileOutputStream.java:256)09-16 19:52:26.654:E/AndroidRuntime(294):at java.io.DataOutputStream.writeBytes(DataOutputStream。java:167)
我面臨同樣的問題..但如果我將「su」更改爲「sh」 那麼它就起作用(至少不會引發破管異常) – DeltaCap