Android java.net.UnknownHostException: host not resolved

This code does not work:

URL url = new URL( xmlPath ); InputSource input = new InputSource( url.openStream() ); 

all the time, leading to an UnknownHostException exception, even when the host exists, it was successful using the same code if from a different development node (machine), as well as from the browser.

I'm probably out of order, asking this question again, I will repeat Android java.net.UnknownHostException: Host is not resolved (strategy question). The forum software would not allow me to comment on the unsatisfactory answer to this question (in order to pay more attention to the solution that I ultimately found). Maybe I'm not popular enough to get this privilege. In the meantime, I am essentially rewriting the question and the other answer.

Basically, I agree that, perhaps, the Android device in certain circumstances is having difficulties with DNS, but I tried, for example, anddev.org example on how to use the SAX analyzer, and it worked on the same machine I have, not on the other.

Edit: As already noted, I know a working answer and will post it.

I a) ask a question (which has already been asked and answered unsuccessfully) and b) answering it in the interests of those for whom my answer will be useful.

+50
android
Aug 18 '10 at 16:36
source share
17 answers

The answer is devilishly simple: delete, then recreate your AVD (virtual device / emulator) in Eclipse. It worked for me - for the first time.

+69
Aug 18 '10 at 16:38
source share

I followed the steps above, but still try to be out of luck, finally, I just understand that my application does not allow me to go beyond the Internet in the emulator. Therefore, simply add user rights to the manifest file. Done! Thanks jozsi see http://www.helloandroid.com/tutorials/how-download-fileimage-url-your-device

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.READ_PHONE_STATE
+54
Jun 16 2018-11-11T00:
source share

In my case, I downloaded the XML file from the URL on my phone, but described the problem in this thread.

to fix it, I had to not only have regular permission to access the Internet

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

But I also need

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

As a prerequisite, in order to find out if your device might need the same thing, try navigating to the URL in your phone’s browser to see if there are any tips on whether to use an SD card or something like that.

Hope this helps others.

+14
Jul 08 2018-12-12T00:
source share

I also saw this on the phone (when debugging USB). The solution was to turn off WiFi and turn it back on.

+13
Feb 13 '11 at 16:22
source share

It works for me, adding user permission for the Internet in the AndroidMenifest.xml file

 <uses-permission android:name="android.permission.INTERNET"/> 
+8
Sep 10
source share

You need to enable the Internet in the emulator.

  • Open emulator

  • Press the menu button and open "settings"

  • Open "wireles and network"

  • Open Mobile Networks

  • Check "Data Resolution"

Now check your application again.

+6
Jun 07 2018-12-12T00:
source share

In my case, the problem was elsewhere. I had to:

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

  • configure the proxy server on my emulator: Emulator > settings > wireless and network > Mobile Networks > Access Point Name > "the access point you have ;)" . Here you can set all proxy server url and username / password you want.

AND

  • Call my network operation in a separate thread. An easy way was to implement AsynchTask.

I found a solution here:

HTTP does not work in Android emulator

“This exception exists for some reason. Network activity may take some time, network execution in the main thread, which is the same thread responsible for updating the user interface, will freeze the thread until network interaction (this is what happens in each thread, but when it was executed on a dedicated thread, this is normal.) In Android, if the UI thread is inactive for 5 seconds, it will show that the application is not responsive, do you want to close it? Dialog. "

+6
Nov 06
source share

I could not get rid of the "UnknownHostExceptions" emulator - and the emulator browser also did not receive the connection. I tried all the suggestions that I could find when the stack overflowed and everywhere.

Finally, I deleted my AVD, turned off Eclipse, and then created the AVD via the command line. Then they started it through the command line with -dns-server 8.8.8.8. (on my Mac: ./ emulator -avd google-8 -dns-server 8.8.8.8) It finally worked!

Hope this helps someone else.

+5
Dec 16 '11 at 22:47
source share

Thank you so much. I'm glad you persisted. I spent most of the hour reading all the possible fixes for this error. Just for someone else stumbling on this topic, I will briefly explain here: -Check Internet uses resolution in the manifest -Exclusion of an exception (meaningless) -Change the firewall settings in the OS -Close the connection (windows only) And download other material

My fix took a little more than yours, but not much. After reading the message, I closed and destroyed all emulators. Then I noticed that when I crossed the start button (green circle with a white arrow), he said that the program was already running, although AVDs (emulators) did not exist! In any case, a restarted eclipse created an AVD and launched it, and Bob was my brother father. Nothing to do with my code or setup.

I found this later. He may very well achieve the same, but I cannot vouch for him if the problem does not recur. http://www.jiahaoliuliu.com/2011/02/stopping-android-applications-already.html Another trick that / can / achieve the same result is the checkbox “erase user data” in the “Run configuration” tab, tab "Goal".

+3
Jun 06 '11 at 20:29
source share

My problem was sharing the Internet from my computer via WIFI after the Ethernet connection was lost and reconnected. I could not contact the phone. This has been fixed by restarting Internet sharing on the computer.

Hope this helps someone.

+3
Apr 11 2018-12-12T00:
source share

In my case, I used a host name based URL with HttpURLConnection. However, using an IP-based URL, the problem was resolved. I also deleted / recreated AVD, but that did not help.

+2
May 30 '12 at 11:14
source share

I just restart AVD and add User Permission, after which it works.

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

+2
Sep 10
source share

problem resolved

run cd C: \ Program Files \ Android \ android-sdk \ tools

run the android avd sheet in cmd returns ur availabe avd list .... in my case its Myabc_avd

run the emulator @Myabc_avd -dns-server 8.8.8.8 in cmd ... avd will show avd go to the avd browser and enter www.google.com to display the google page. u can now access the browser using the host name, for example myfrstapp.com

if everything goes well then you can start the ur project using eclipse, but make sure it works in avd, which runs from cmd.

+2
02 Feb '13 at 9:28
source share

In my case, I just restarted the emulator and it worked.

0
Jan 15 '14 at 8:18
source share

It is so simple. No need to restart eclipse OR remove and create an emulator, you just need to follow these steps:

  • Right click on your project
  • Click Run As
  • Click Run Configuration
  • The window opens.
  • In the left pane, select the project launch configuration.
  • Then in the right pane, click the Target tab.
  • Scroll down
  • You will get the option below called " Command line arguments for the optional emulator "
  • Put " -dns-server 8.8.8.8 " these values ​​( without double quotes ) in the text box.

What is it...

0
Oct 17 '14 at 12:49 on
source share

I ran into this problem when I started the emulator when I connected to the VPN. Exiting the VPN did not affect until I left the emulator and restarted it. It is easy to verify that your emulator resolves names correctly - just go to the emulator browser and enter the hostname of the website.

0
Sep 30 '16 at 18:55
source share

Please try restarting the emulator.

0
Apr 19 '19 at 2:29
source share



All Articles