wood burning stoves 2.0*
The moose likes Android and the fly likes host unresolved error!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "host unresolved error!! " Watch "host unresolved error!! " New topic
Author

host unresolved error!!

beta jane
Greenhorn

Joined: Oct 07, 2009
Posts: 14


Hi iam using sdk 1.6,my browser works fine nd iam able to connect to all sites fromit.Iam behind proxy.
Iam not able to connect to gmail through my code,when i do it,i get host unresolved error.
I surfed regarding this error and found it to be something common,but none of the sites and blogs gave a solution to this problem.
I have given internet permissions in manifest file too.
The application basically tries to login to gmail with proper authentication and is supposed to fetch google contacts to emulator.
But iam not able to proceed further as i get this error please help me out!!
Any valuable suggestion welcome.
Thanks in advance

Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

You get UnResolvedHost error because the client cannot connect to the remote machine. When you are sitting behind a proxy, you should set the proxy IP and port number in the class doing the transport. I have used DefaultHttpClient class for all of my GET and POST requests. This is how I set proxy(see if you can do something similar):



my 2 cents..


[List of FAQs] | [Android FAQ] | [Samuh Varta]
beta jane
Greenhorn

Joined: Oct 07, 2009
Posts: 14
Hi thnx for a reply

my doubt is that,i have already set the proxy and port number in my emulator apn settings.Should
I do the same through my code too?





shoild i set mr port number in above line??
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Setting the proxy in your APN settings will help you use your emulator Browser; I think, you will have to find a way to set proxy from your code.
BTW, the code snippet I posted, is for making proxy settings in the DefaultHttpClient class.
beta jane
Greenhorn

Joined: Oct 07, 2009
Posts: 14
ok thnx!!

so how sholud i proceed!! Iam new to this whole technology and iam not aware as to how to use your code snippet in my code
Please help
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

I notice you are using a custom class for doing the transport: import com.example.socapp.HTTPRequestHelper;
You can try and find a way to make proxy settings in your HTTPRequestHelper class. Without knowing what this class is, I cant say much.
I generally use DefaultHttpClient class that comes with default android.jar to do my transport and the code snippet I posted in my reply above, configures the proxy for me.
Alternatives:
1. you can try to turn off the proxy and try your code
2. If you try your code on the actual device instead of emulator, and if the problem in your code is with the proxy settings alone, you can be assured that your code will work.
beta jane
Greenhorn

Joined: Oct 07, 2009
Posts: 14
thnx....!!

the following is my HTTPRequestHelper class...
I dont have a device and hence iam left with no option other than the emulator.

Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Hmmmm...

Your HttpRequestHelper class is using the DefaultHttpClient class. Here is what you can try:

copy the following setProxy() method in your HttpRequestHelper class.

Note: Replace the IP/port# with the IP/port# for your proxy. Also, give your username and password as argument to set credentials.

Call this setProxy() method from the performRequest() method of the HttpRequestHelper class specifically, below the line where you instantiate the DefaultHttpClient class:

That should set the proxy.

Hope that helps...

Note: you will have to comment out setProxy() when you are runnning your code on actual device or your transport wont work.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: host unresolved error!!
 
Similar Threads
Httppost Problem
SOAP validateUser
Cannot find the problem in the code
SharedPreference not working
how to add a google search option