【问题标题】:Echo the content of a TextView?回显 TextView 的内容?
【发布时间】:2013-09-28 06:13:52
【问题描述】:

我有一个使用此代码的课程

public boolean busybox() throws IOException
{

        try
        {

        Process p =Runtime.getRuntime().exec("busybox");
        InputStream a = p.getInputStream();
        InputStreamReader read = new InputStreamReader(a);
        BufferedReader in = new BufferedReader(read);
        StringBuilder buffer = new StringBuilder();

        String line = null;

        try {

            while ((line = in.readLine()) != null) {
                buffer.append(line);
            }

        } finally {
            read.close();
            in.close();
        }

        String result = buffer.toString().substring(0, 15);
        System.out.println(result);

        return true;
        } catch (Exception e) {
        e.printStackTrace();
    }

        return false;
        }

在另一个班级我有这个代码

try {
    if(root.busybox()) {

        Busybox.setText(Html.fromHtml((getString(R.string.busybox))));


    }
    else {

        Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
            }
        });

如果我想在这个 TextView 中写入 System.out.println(result) 生成的输出;

我该怎么办?提前致谢!我尝试了几次,但我有几个错误,代码是错误的。

【问题讨论】:

  • 哪一行导致异常?能发一下logcat吗?

标签: java android xml root busybox


【解决方案1】:

public boolean busybox() 的返回类型更改为public String busybox()return result 等字符串。

然后使用

try {
String myResult=root.busybox();  
if(myResult!=null&&myResult.length>0) {

    Busybox.setText(Html.fromHtml((myResult)));


}
else {

    Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} 

【讨论】:

  • 它工作。非常感谢。
  • 永远欢迎亲爱的!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-05
  • 1970-01-01
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多