Dragos
Dragos

Reputation: 2991

Android Unable to resolve host

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.

Upvotes: 8

Views: 11150

Answers (2)

Gvstrmrgh
Gvstrmrgh

Reputation: 71

I believe I had the same issue as the OP, I know this is an old question but will post my findings anyway.

The problem is that the Resting framework methods like get() passes the url through its connection helpers, and expects you to provide the port as the second parameter.

So taking OP's example, instead of:

Resting.get('my.ip:8080');

your call should be:

Resting.get('my.ip', 8080)

Hope that helps someone :)

Upvotes: 0

Neto Marin
Neto Marin

Reputation: 674

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.

Upvotes: 1

Related Questions