Android 安卓中的Ping

Android 安卓中的Ping,android,if-statement,android-studio,ping,Android,If Statement,Android Studio,Ping,我在stackoverflow中看到了这一点,我发现了很多结果,但这些答案中的任何一个都对我有用 但其中一种代码在50%的情况下有效 public void GET3() { TextView SYS3; String ip = "www.codelow-dat.site90.com"; String pingResult = ""; String pingCmd = "ping" + ip; Runtime r = Runtime.getRuntim

我在stackoverflow中看到了这一点,我发现了很多结果,但这些答案中的任何一个都对我有用

但其中一种代码在50%的情况下有效

public void GET3() {
    TextView SYS3;

    String ip = "www.codelow-dat.site90.com";
    String pingResult = "";
    String pingCmd = "ping" + ip;

    Runtime r = Runtime.getRuntime();
    Process p = null;
    try {
        p = r.exec(new String[]{"ping", "-c 4", "www.codelow-dat.site90.com"});
    } catch (IOException e) {
        e.printStackTrace();
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String inputLine;
    SYS3 = (TextView) findViewById(R.id.SYS3);
    SYS3.setText(getString(R.string.goingloop)); //going loop
    try {
        while ((inputLine = in.readLine()) != null) {
            pingResult = inputLine;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    SYS3 = (TextView) findViewById(R.id.SYS3);
    SYS3.setTextColor(Color.parseColor("#66CD00"));
    if (Boolean.valueOf(pingResult) == null) {
        SYS3.setTextColor(Color.parseColor("#D61D00"));
        SYS3.setText(getString(R.string.somethingwrong)); //something is wrong
    } else {
        SYS3.setText(pingResult + getString(R.string.IsOk)); //, is OK
    }
    try {
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
“如果”无论如何都不起作用,我什么都试了,但不起作用。当ping错误时,我只看到字符串IsOk(,IsOk),而不是字符串SomethingError(SomethingError)(并将文本颜色更改为红色)


谢谢大家

您是否尝试过检查布尔值是否为假,而不仅仅是空值?是的,我尝试过,但相同;第一次尝试时,我将false改为null。。。