process.getInputStream()在adb命令上返回null

时间:2017-03-19 14:24:06

标签: android android-studio

我正在尝试重新启动下载,但我得到了:

  

尝试调用虚方法' 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

1 个答案:

答案 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()));

}