Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Unable to resolve host

Tags:

android

client

I am new to Android, so this question might have a simple answer(I might have missed something). I am trying to make a REST client with the help of the Resting framework from Google(because Jersey didn't seem to work). When I try to run the client, I get this warning:

W/System.err(728): java.net.UnknownHostException: Unable to resolve host "my.ip:8080": No address associated with hostname

and then I get a few Exceptions, but I guess that this is the root cause.

I have the internet permission:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maze.client"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".RestingClientActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

If you need any additional information, please let me know.

  • In the warning I replaced my IP with "mi.ip"(it is intentionally done, but in the original it is all right).
like image 790
Dragos Avatar asked Feb 19 '12 16:02

Dragos


People also ask

What does no address associated with hostname mean?

The errors Failed host lookup: 'api.xyz.com' and OS Error: No address associated with hostname usually mean that your DNS lookup fails. As hinted by OS Error this is usually a system-level error and nothing specific to http or Dart.

How do you handle an unknown host exception in Java?

A few tips to prevent the exception are: Double-check the hostname: Make sure there is no typo, and trim all whitespaces. Check the system's DNS settings: Make sure the DNS server is up and reachable, and if the hostname is new, wait for the DNS server to catch up.


1 Answers

If you post the piece of code where you do the connection to the server, it will be easier to help you. But, probably your problem is on creating the URI to be called. Example:

URI uri = URIUtils.createURI("http", "your-ip", 8080, "/path/to/webservice", 
        URLEncodedUtils.format(params, "UTF-8"), null);
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(uri);
response = client.execute(get);

So, if you call the execute method with an invalid or a wrong URI, you could have a problem.

Or, sometimes, when you keep your AVD opened and change the network you are using, for example, go out of the office and start using you home wifi, you should get a problem like this you are having.

like image 194
Neto Marin Avatar answered Oct 04 '22 16:10

Neto Marin