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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With