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();
            }    
2
  • 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 Commented Dec 27, 2011 at 9:15
  • change your hostname to host ip address, that should solve your problem. Commented Jan 30, 2012 at 12:00

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

yes, it may be the device network connectivity on which I am running the application.
change your hostname to host ip address, that should solve your problem.
0

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

Comments

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,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.