无法解析主机“”;没有与主机名相关联的地址

时间:2022-09-03 21:39:29

In my Android application for reading RSS links, I am getting this error:

在我的Android应用程序中读取RSS链接,我得到了这个错误:

java.net.UnknownHostException: Unable to resolve host "example.com"; No address associated with hostname.

net. unknownhostexception:无法解析主机“example.com”;没有与主机名相关联的地址。

In my emulator I can connect to Google through a browser. Please help me to resolve this issue.

在模拟器中,我可以通过浏览器连接到谷歌。请帮助我解决这个问题。

17 个解决方案

#1


141  

You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:

你可能没有网络许可。尝试将此添加到您的AndroidManifest中。xml文件,在之前:

<uses-permission android:name="android.permission.INTERNET" />

#2


47  

I've seen this problem in the emulator as well. In my case, it is caused by launching the emulator, then putting the computer to sleep or changing the network connection (going from work to home, etc), then attempting to use the same emulator again. Closing and re-launching the emulator resolves the problem in this case.

我在模拟器中也见过这个问题。在我的例子中,它是通过启动仿真器,然后让计算机休眠或更改网络连接(从工作到家庭等等),然后再尝试使用相同的仿真器来引起的。关闭和重新启动仿真器解决了这个问题。

#3


31  

Unable to resolve host “”; No address associated with hostname

无法解析主机“”;没有与主机名相关联的地址

you must have to check below code here on your manifest :

您必须在您的清单上检查以下代码:

<uses-permission android:name="android.permission.INTERNET" />

and most important at least for me:-

至少对我来说最重要的是:-

enabled wifi connection or internet connection on your mobile device

在您的移动设备上启用wifi连接或互联网连接。

#4


29  

It is WiFi bug due to wifi disable or not properly connected.

它是WiFi故障,因为WiFi被禁用或连接不正确。

Simply Reconnect the wifi will solve the issue.

只要重新连接wifi就可以解决这个问题。

#5


7  

Sometimes, although you add <uses-permission android:name="android.permission.INTERNET" /> in the AndroidManifest and you have a WiFi connection, this exception can be thrown. In my case, I have turned off WiFi and then turned it on again. This resolved the error. Weird solution, but sometimes it works.

有时,尽管您添加了

#6


6  

"" it seems you are trying to resolve this host , which is invalid.

“看来你是在试图解析这个主机,它是无效的。”

Check for rss URL

检查rss URL

Update Following are the possibilities

以下是更新的可能性

1 Your browser is configured with proxy, app not

你的浏览器配置了代理,而不是app

System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");

2 Your browser has access to internet. not app

你的浏览器可以上网。没有应用程序

3 can be an SSL issue if URL is secured

如果URL是安全的,则可能是SSL问题

#7


4  

It could be due to below reasons: -

这可能是由于以下原因:-

  1. Either you dont have INTERNET permission in manifest file. If so then please use this statement <uses-permission android:name="android.permission.INTERNET" />

    或者你在manifest文件中没有互联网权限。如果是,请使用此语句

  2. Or you are connected to a network but your internet connection is not working. Like you are connected to a Wi-Fi but it doesnt have internet connection or Mobile data on your phone is ON but you dont have data connectivity on your phone.

    或者你连接到一个网络,但是你的网络连接不工作。就像你连接Wi-Fi,但它没有网络连接或手机上的移动数据,但你的手机上没有数据连接。

Point# 2 is interesting and its not assumption, I have tested the same at my end.

第2点很有趣,它不是假设,我在我这边也做了同样的测试。

Hope this will help you

希望这能对你有所帮助

Summved

Summved

#8


2  

It's not your fault bae, I've had this happen sometimes when the emulator's in a weird state. Just restarting the emulator helped me.

这不是你的错,bae,我有过这种情况当模拟器处于一个奇怪的状态时。只要重新启动模拟器就可以帮助我了。

#9


2  

Some times on the emulator, I have to launch the browser before my app can access the Internet.

在模拟器上的一些时候,我必须先启动浏览器才能让我的应用程序访问互联网。

#10


1  

If you are running the app on an emulator, make sure that it is properly connected to the internet. If it is not, the easiest way of solving it is reopening the emulator or creating a new device.

如果您正在模拟器上运行应用程序,请确保它正确地连接到internet。如果不是,最简单的解决方法就是重新打开模拟器或者创建一个新设备。

#11


1  

Check permission for INTERNET in mainfest file and check network connectivity.

在mainfest文件中检查网络权限,检查网络连接。

#12


1  

I Had the same problem, and it was because the simulator somehow got in airplane mode, once this was disabled my App worked fine :-) I had tried everything, rebuild, clean+build and reboot android studio and reboot the computer, even reinstalling android studio..

我遇到了同样的问题,这是因为模拟器以某种方式进入了飞机模式,一旦禁用,我的应用程序就会运行良好:-)我尝试过一切,重建,清洁+构建和重启android studio,重启电脑,甚至重新安装android studio..

#13


1  

In my case, I had that error when I'm connected to VPN on my host but not on simulator. Turning the VPN off solved the issue

在我的例子中,当我在我的主机上而不是在模拟器上连接到VPN时,我有这个错误。关闭VPN解决了问题

#14


1  

Unable to resolve host “”; No address associated with hostname

无法解析主机“”;没有与主机名相关联的地址

I had this issue and I solved it by this way. change

我有这个问题,我用这种方法解决了它。改变

http://hostname/abc/def/ghi/name.php

http://hostname/abc/def/ghi/name.php

to

http://ipaddress/abc/def/ghi/name.php //http://97.68.XX.YY/abc/def/ghi/name.php

http://ipaddress/abc/def/ghi/name。php / / http://97.68.XX.YY/abc/def/ghi/name.php

I solved this by this way...you have to give server ip address instead of hostname/servername.

我用这种方法解决了这个问题……您必须提供服务器ip地址而不是主机名/服务器名。

Please try this and comment your feedback.

请尝试并评论您的反馈。

#15


1  

In my case problem was with WIFI working with IPV6 and my domain did not have IPv6 adress

在我的例子中,WIFI使用IPV6时出现了问题,而我的域名没有IPV6地址

#16


1  

Check you have:

检查你有:

1- Access to Internet connectivity.

1-连接互联网。

2- The permission for internet is present in the manifest.

2-舱单内载有互联网使用许可。

3- The url host is valid and register in a trusted domain name server.

3- url主机是有效的,并在可信域名服务器中注册。

#17


1  

I had the same issue. My virtual device was showing a crossed-out WiFi icon at the top bar of the device. I rebooted the virtual device and everything was back to normal.

我也有同样的问题。我的虚拟设备在设备的顶部栏显示了一个交叉的WiFi图标。我重启了虚拟设备,一切恢复正常。

#1


141  

You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:

你可能没有网络许可。尝试将此添加到您的AndroidManifest中。xml文件,在之前:

<uses-permission android:name="android.permission.INTERNET" />

#2


47  

I've seen this problem in the emulator as well. In my case, it is caused by launching the emulator, then putting the computer to sleep or changing the network connection (going from work to home, etc), then attempting to use the same emulator again. Closing and re-launching the emulator resolves the problem in this case.

我在模拟器中也见过这个问题。在我的例子中,它是通过启动仿真器,然后让计算机休眠或更改网络连接(从工作到家庭等等),然后再尝试使用相同的仿真器来引起的。关闭和重新启动仿真器解决了这个问题。

#3


31  

Unable to resolve host “”; No address associated with hostname

无法解析主机“”;没有与主机名相关联的地址

you must have to check below code here on your manifest :

您必须在您的清单上检查以下代码:

<uses-permission android:name="android.permission.INTERNET" />

and most important at least for me:-

至少对我来说最重要的是:-

enabled wifi connection or internet connection on your mobile device

在您的移动设备上启用wifi连接或互联网连接。

#4


29  

It is WiFi bug due to wifi disable or not properly connected.

它是WiFi故障,因为WiFi被禁用或连接不正确。

Simply Reconnect the wifi will solve the issue.

只要重新连接wifi就可以解决这个问题。

#5


7  

Sometimes, although you add <uses-permission android:name="android.permission.INTERNET" /> in the AndroidManifest and you have a WiFi connection, this exception can be thrown. In my case, I have turned off WiFi and then turned it on again. This resolved the error. Weird solution, but sometimes it works.

有时,尽管您添加了

#6


6  

"" it seems you are trying to resolve this host , which is invalid.

“看来你是在试图解析这个主机,它是无效的。”

Check for rss URL

检查rss URL

Update Following are the possibilities

以下是更新的可能性

1 Your browser is configured with proxy, app not

你的浏览器配置了代理,而不是app

System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");

2 Your browser has access to internet. not app

你的浏览器可以上网。没有应用程序

3 can be an SSL issue if URL is secured

如果URL是安全的,则可能是SSL问题

#7


4  

It could be due to below reasons: -

这可能是由于以下原因:-

  1. Either you dont have INTERNET permission in manifest file. If so then please use this statement <uses-permission android:name="android.permission.INTERNET" />

    或者你在manifest文件中没有互联网权限。如果是,请使用此语句

  2. Or you are connected to a network but your internet connection is not working. Like you are connected to a Wi-Fi but it doesnt have internet connection or Mobile data on your phone is ON but you dont have data connectivity on your phone.

    或者你连接到一个网络,但是你的网络连接不工作。就像你连接Wi-Fi,但它没有网络连接或手机上的移动数据,但你的手机上没有数据连接。

Point# 2 is interesting and its not assumption, I have tested the same at my end.

第2点很有趣,它不是假设,我在我这边也做了同样的测试。

Hope this will help you

希望这能对你有所帮助

Summved

Summved

#8


2  

It's not your fault bae, I've had this happen sometimes when the emulator's in a weird state. Just restarting the emulator helped me.

这不是你的错,bae,我有过这种情况当模拟器处于一个奇怪的状态时。只要重新启动模拟器就可以帮助我了。

#9


2  

Some times on the emulator, I have to launch the browser before my app can access the Internet.

在模拟器上的一些时候,我必须先启动浏览器才能让我的应用程序访问互联网。

#10


1  

If you are running the app on an emulator, make sure that it is properly connected to the internet. If it is not, the easiest way of solving it is reopening the emulator or creating a new device.

如果您正在模拟器上运行应用程序,请确保它正确地连接到internet。如果不是,最简单的解决方法就是重新打开模拟器或者创建一个新设备。

#11


1  

Check permission for INTERNET in mainfest file and check network connectivity.

在mainfest文件中检查网络权限,检查网络连接。

#12


1  

I Had the same problem, and it was because the simulator somehow got in airplane mode, once this was disabled my App worked fine :-) I had tried everything, rebuild, clean+build and reboot android studio and reboot the computer, even reinstalling android studio..

我遇到了同样的问题,这是因为模拟器以某种方式进入了飞机模式,一旦禁用,我的应用程序就会运行良好:-)我尝试过一切,重建,清洁+构建和重启android studio,重启电脑,甚至重新安装android studio..

#13


1  

In my case, I had that error when I'm connected to VPN on my host but not on simulator. Turning the VPN off solved the issue

在我的例子中,当我在我的主机上而不是在模拟器上连接到VPN时,我有这个错误。关闭VPN解决了问题

#14


1  

Unable to resolve host “”; No address associated with hostname

无法解析主机“”;没有与主机名相关联的地址

I had this issue and I solved it by this way. change

我有这个问题,我用这种方法解决了它。改变

http://hostname/abc/def/ghi/name.php

http://hostname/abc/def/ghi/name.php

to

http://ipaddress/abc/def/ghi/name.php //http://97.68.XX.YY/abc/def/ghi/name.php

http://ipaddress/abc/def/ghi/name。php / / http://97.68.XX.YY/abc/def/ghi/name.php

I solved this by this way...you have to give server ip address instead of hostname/servername.

我用这种方法解决了这个问题……您必须提供服务器ip地址而不是主机名/服务器名。

Please try this and comment your feedback.

请尝试并评论您的反馈。

#15


1  

In my case problem was with WIFI working with IPV6 and my domain did not have IPv6 adress

在我的例子中,WIFI使用IPV6时出现了问题,而我的域名没有IPV6地址

#16


1  

Check you have:

检查你有:

1- Access to Internet connectivity.

1-连接互联网。

2- The permission for internet is present in the manifest.

2-舱单内载有互联网使用许可。

3- The url host is valid and register in a trusted domain name server.

3- url主机是有效的,并在可信域名服务器中注册。

#17


1  

I had the same issue. My virtual device was showing a crossed-out WiFi icon at the top bar of the device. I rebooted the virtual device and everything was back to normal.

我也有同样的问题。我的虚拟设备在设备的顶部栏显示了一个交叉的WiFi图标。我重启了虚拟设备,一切恢复正常。