I got this error when executing a command in Android shell via runtime.getRuntime.exec(command,arguments,working directory)b
FATAL EXCEPTION: main
04-07 02:56:18.539 23705 23705 E AndroidRuntime Process: com.learning, PID: 23705
04-07 02:56:18.539 23705 23705 E AndroidRuntime java.lang.NullPointerException: taintedCommand[1] == null
04-07 02:56:18.539 23705 23705 E AndroidRuntime at java.lang.ProcessManager.exec(ProcessManager.java:184)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at java.lang.Runtime.exec(Runtime.java:174)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.learning.BackgroundJob.<init>(BackgroundJob.java:38)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.learning.MainActivityTerminal$100000000.onEditorAction(MainActivityTerminal.java:58)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at android.widget.TextView.onEditorAction(TextView.java:4489)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:143)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:304)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:102)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at android.os.Looper.loop(Looper.java:135)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:5318)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:372)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922)
04-07 02:56:18.539 23705 23705 E AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717)
04-07 02:54:04.839 23439 23439 W System.err at java.lang.reflect.Method.invoke(Method.java:372)
04-07 02:54:04.839 23439 23439 W System.err at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922)
04-07 02:54:04.839 23439 23439 W System.err at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717)
04-07 02:54:04.839 23439 23439 W System.err Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
04-07 02:54:04.839 23439 23439 W System.err at libcore.io.Posix.open(Native Method)
04-07 02:54:04.839 23439 23439 W System.err at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
04-07 02:54:04.839 23439 23439 W System.err at libcore.io.IoBridge.open(IoBridge.java:442)
04-07 02:54:04.839 23439 23439 W System.err ... 18 more
code
Process process;
try {
process = Runtime.getRuntime().exec(progArray, env, new File(cwd));
} catch (IOException e) {
mProcess = null;
// TODO: Visible error message?
Log.e(LOG_TAG, "Failed running background job: " + processDescription, e);
return;
}
variables progarry command to execute, env current environment, cwd current working directory.
Runtime.exec()
throws aNullPointerException
ifcmdarray
isnull
, or one of the elements ofcmdarray
isnull
, or one of the elements ofenvp
isnull
.So, the best you can do is to check for these conditions, for example