Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
java.net.UnknownHostException error in android
how can i solve this problem.
Posted
Comments
Sergey Alexandrovich Kryukov 4-May-15 1:15am    
Not enough information.
—SA
Member 11420908 4-May-15 1:21am    
This is my code.
TextView textv = (TextView)findViewById(R.id.txt1);
// webView=(WebView)findViewById(R.id.webView);
// webView.loadUrl("http://kredo.no-ip.org/SSMA/api/DevicesAPI/GetDevices");
textv.setText("Text Has Been Changed");
BufferedReader in = null;
String data = null;
try{
HttpClient httpclient = new DefaultHttpClient();

HttpGet request = new HttpGet();
URI website = new URI("http://kredo.no-ip.org/SSMA/api/DevicesAPI/GetDevices");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));

// NEW CODE
String line = in.readLine();
textv.append(" First line: " + line);
// END OF NEW CODE

textv.append(" Connected ");
}catch(Exception e){
Log.e("log_tag", "Error in http connection " + e.toString());
}

1 solution

Not enough information, but… you cannot just "fix" it. You are doing something with the host address/name which does not actually exist. It could be host name not prescribed in DNS, something like that.

—SA
 
Share this answer
 
Comments
Member 11420908 4-May-15 1:30am    
hi i just trying to show details from url in a textview by sollwing method.
whenever i run the code it throw a exception "java.net.UnknownHostException"

the code is:
class Apical extends AsyncTask
{
@Override
protected Object doInBackground(Object[] params) {

TextView textv = (TextView)findViewById(R.id.txt1);
textv.setText("Text Has Been Changed");
BufferedReader in = null;
String data = null;
try{
HttpClient httpclient = new DefaultHttpClient();

HttpGet request = new HttpGet();
URI website = new URI("http://kredo.no-ip.org/SSMA/api/DevicesAPI/GetDevices");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));

// NEW CODE
String line = in.readLine();
textv.append(" First line: " + line);
// END OF NEW CODE

textv.append(" Connected ");
}catch(Exception e){
Log.e("log_tag", "Error in http connection " + e.toString());
}

return null;
}
}
Sergey Alexandrovich Kryukov 4-May-15 1:55am    
In what line?
—SA
Member 11420908 4-May-15 2:18am    
Hi
i have test the all code with break point it't throw any exception during debug but when i run the code it shows java.net.unknownexception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900