Java - java.net.NoRouteToHostException:无主机路由:connect

时间:2012-02-23 00:36:46

标签: java if-statement connection

我有一个类,如果有连接,则从URL返回数据字符串,否则返回null。

我的问题是我正在检查:

if (str == null) {
   System.out.println("Error: No Connection");
}

然而,尽管这个DOES有效,但它也会在控制台中打印出来:

java.net.NoRouteToHostException: No route to host: connect

我想知道这意味着什么,如果它暗示我犯了错误?虽然程序工作正常,但其他这个小异常不断涌现。帮助

1 个答案:

答案 0 :(得分:0)

完全猜测,直到你发布更多代码......但我猜你在打印你的消息返回str后忘记返回,如果不是它会尝试执行你的其余代码..

private String myFunction(String url){
    if (str == null) {
       System.out.println("Error: No Connection");
       return null;
    }
    //do other stuff that you are already doing .

}
相关问题