java.net.UnknownHostException:服务器主机名无效:本地 [英] java.net.UnknownHostException: Invalid hostname for server: local

查看:59
本文介绍了java.net.UnknownHostException:服务器主机名无效:本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该采取哪些步骤来解决错误:

java.net.UnknownHostException:服务器主机名无效:本地

我在 Android 模拟器上添加了新的虚拟主机名,但结果返回到

 java.net.UnknownHostException virtualhostname atjava.net.InetAddress.lookUpHostByName(InetAddress.java:506)

当我在我的 PC 上输入我的虚拟主机 URL 时,它可以正常显示.然后,当我在 Emulator 上运行并检查 Logcat 时,如果 200、202 或错误代码号,我将无法读取或检查 HTTP 状态.它只是返回到 UnknownHostException

解决方案

真正意义上的例外是没有名为local"的已知服务器.我的猜测是您正在尝试连接到本地计算机.尝试使用主机名 "localhost",或者 127.0.0.1::1(最后一个是 IPv6).

来自 javadocs:><块引用>

抛出表示IP地址无法确定主机.

127.0.0.1::1"localhost" 应该总是环回接口,所以如果这不起作用我会很惊讶.

如果您的网络上确实有一个名为本地"的服务器 - 检查您的 DNS 设置或将其添加到您的主机文件中.

What are the steps I should take to solve the error:

java.net.UnknownHostException: Invalid hostname for server: local

I added the new virtual host name at Android emulator but the result returns to

 java.net.UnknownHostException virtualhostname at 
  java.net.InetAddress.lookUpHostByName(InetAddress.java:506)

When I type my virtualhost URL on my PC, it works on display. Then again, when I ran on Emulator and check on Logcat, I couldn't be able to read or check the HTTP status if 200, 202, or an error code number. It simply returned to UnknownHostException

解决方案

What the exception is really saying is that there is no known server with the name "local". My guess is that you're trying to connect to your local computer. Try with the hostname "localhost" instead, or perhaps 127.0.0.1 or ::1 (the last one is IPv6).

From the javadocs:

Thrown to indicate that the IP address of a host could not be determined.

127.0.0.1or ::1 or "localhost" should always be the loopback interface, so if that doesn't work I'd be really surprised.

If there really is a server called "local" on your network - examine your DNS settings or add it to your hosts file.

这篇关于java.net.UnknownHostException:服务器主机名无效:本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆