4

I m implementing android app in that I m working on web api. Sometimes my app gets connected to webserver but sometimes it throws exception as java.net.UnknownHostException: Host is unresolved: webservername.com:80. I m fetching json response from api.

I m using fetching code as following:

    String queryResult  =   null;
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    try {
            request.setURI(new URI(archiveQuery));
    } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    //HttpResponse response = client.execute(request, new BasicResponseHandler());
            try {
                queryResult =   client.execute(request, new BasicResponseHandler());
            }
            catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }    
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • 1
    running in emulator/device check whether the broswer can open any site,internet connection is slow or not available...this you might be running in emulator..and emulator didn't got net connection so this happend – MKJParekh Dec 27 '11 at 09:15
  • change your hostname to host ip address, that should solve your problem. – Mukunda Jan 30 '12 at 12:00

3 Answers3

0

The Answer is really very simple. You need to Restart the emulator.Check out this

Community
  • 1
  • 1
Nishant
  • 32,082
  • 5
  • 39
  • 53
0

Just restart adb, find adb.exe in your adt bundle and double click it. Some shit will happen on command prompt, and there you go, restart your emulator and it should work fine,

Sushil Lakra
  • 67
  • 2
  • 7
0

I think it's a DNS issue of your server, according to your comments. Sometimes you ping, sometimes you don't, but on your browser it always work? Surely it's a server connectivity issue.

Vicente Plata
  • 3,370
  • 1
  • 19
  • 26