Android java.net.UnknownHostException: Host is unresolved

前端 未结 17 1007
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 08:43

This code doesn\'t work:

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

all the time, res

相关标签:
17条回答
  • 2020-12-01 09:27

    It work's for me by adding user's permission for Internet in AndroidMenifest.xml file

    <uses-permission android:name="android.permission.INTERNET"/>
    
    0 讨论(0)
  • 2020-12-01 09:27

    I couldn't get rid of the emulator "UnknownHostExceptions" - and the emulator's browser wouldn't get a connection either. Tried all suggestions I could find at stack overflow and everywhere else.

    Finally I deleted my AVD, shut down Eclipse, and then created the AVD via the command line. Then launched it via command line with the -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.

    0 讨论(0)
  • 2020-12-01 09:27

    I just restart the AVD and add the User Permission then it works.

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

    0 讨论(0)
  • 2020-12-01 09:31

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

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

    • setup a 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 the proxy port url and login/pass you want.

    AND

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

    I found the solution here:

    HTTP doesn't work in Android emulator

    " This exception is there for a reason. Network activity can take time, performing networking on the main thread, which is the same thread that responsible for updating the UI, would freeze the thread until the networking is done (this is what happens on every thread, but when it's performed on a dedicated thread, it's ok). In Android, if the UI-thread isn't active for 5 seconds, it will show the Application is not responsive, Do you want to close it? dialog. "

    0 讨论(0)
  • 2020-12-01 09:33

    Thank you so much Russ. I'm glad you persisted. I had spent the best part of an hour reading all kinds of possible fixes to this error. Just for anyone else stumbling across this thread, i'll briefly recap here: -Check Internet uses permission is in the manifest -Catching the exception (pointless) -Changing firewall settings on your OS -Share connection (windows only) And a load of other stuff

    My fix took a little more than yours, but not much. After reading your post, I closed and destroyed all emulators. Then I noticed that when I moused over the run button (green circle with white arrow) it said the program was already running, even though no AVDs (emulators) existed! Anyway, restarted eclipse, created a AVD and ran it and Bob was my father's brother. Nothing to do with my code or setup at all.

    I found this afterwards. It may well achieve the same thing but I can't vouch for it unless the problem reoccurs. http://www.jiahaoliuliu.com/2011/02/stopping-android-applications-already.html Another trick that /may/ achieve the same result is tick "wipe user data" in Run Configurations, Target tab.

    0 讨论(0)
  • 2020-12-01 09:34

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

    0 讨论(0)
提交回复
热议问题