InetAddress.getByName on Android

前端 未结 4 1773
别跟我提以往
别跟我提以往 2020-12-11 17:53

I do a:

java.net.InetAddress serverAddr;
try {
    serverAddr = java.net.InetAddress.getByName(Server.SERVERNAME);
}
catch (java.net.UnknownHostException exc         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-11 18:21

    I've found the answer. For whatever reason, you have to use:

    java.net.InetAddress[] x= java.net.InetAddress.getAllByName(Server.SERVERNAME) ; HelloWorldActivity.tv.setText("Address: "+x[0].getHostAddress());

提交回复
热议问题