我正在尝试重新启动下载,但我得到了:
尝试调用虚方法' java.io.InputStream java.lang.Process.getInputStream()'在空对象引用上
代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] s ={"adb", "reboot", "download"};
Process p = null;
try {
p = Runtime.getRuntime().exec(s);
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
}
我试图把代码放到不同的线程中。
为什么process.getInputStream()
在null
命令上返回adb
?
答案 0 :(得分:0)
尝试删除Process p = null
,并在try
正文中实施:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] s ={"adb", "reboot", "download"};
try {
Process p = Runtime.getRuntime().exec(s);
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
}