Java unknown host exception

女生的网名这么多〃 提交于 2019-12-19 05:13:12

问题


I am trying to access textalertapp.com via HTTP Post request from my android application. But I am getting Unknown host error. Can anybody help me solve this issue.

12-13 01:30:16.058: WARN/System.err(473): java.net.UnknownHostException: textalertapp.com
    12-13 01:30:16.088: WARN/System.err(473):     at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
    12-13 01:30:16.088: WARN/System.err(473):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
    12-13 01:30:16.088: WARN/System.err(473):     at java.net.InetAddress.getAllByName(InetAddress.java:242)
    12-13 01:30:16.088: WARN/System.err(473):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
    12-13 01:30:16.099: WARN/System.err(473):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
    12-13 01:30:16.099: WARN/System.err(473):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
    12-13 01:30:16.099: WARN/System.err(473):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
    12-13 01:30:16.108: WARN/System.err(473):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    12-13 01:30:16.118: WARN/System.err(473):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    12-13 01:30:16.118: WARN/System.err(473):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    12-13 01:30:16.118: WARN/System.err(473):     at com.textalert.alertCollection.getAlerts(alertCollection.java:46)
    12-13 01:30:16.118: WARN/System.err(473):     at com.textalert.alertsList$1.run(alertsList.java:81)
    12-13 01:30:16.128: WARN/System.err(473):     at java.lang.Thread.run(Thread.java:1096)

Code is

 HttpClient client = new DefaultHttpClient();
                String postURL = "http://textalertapp.com/androidCode/?api=AlertManager&method=getAlerts";
                HttpPost post = new HttpPost(postURL); 

                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("user", "kris"));
                params.add(new BasicNameValuePair("pass", "xyz"));
                UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
                post.setEntity(ent);
                HttpResponse responsePOST = client.execute(post);  
                HttpEntity resEntity = responsePOST.getEntity();  
                if (resEntity != null) {    
                    Log.i("RESPONSE",EntityUtils.toString(resEntity));
                }

回答1:


<uses-permission android:name="android.permission.INTERNET"></uses-permission>

I just added this line in manifest file. Problem solved




回答2:


This means that your host is unknown, i.e. does not exist or is not accessible. Check you IP again and check whether you can get this IP from your device. Probably this IP exists in your local network and is not accessible from outside.

If IP exists check firewall definitions. Firewall cause the same effect.




回答3:


I just started receiving the "java.net.UnknownHostException" error when fetching content from a URL that previously worked perfectly.

After going around in circles for a while, I manually deleted my project's /bin folder and cleaned the project in Eclipse (Project -> Clean), which fixed this error.



来源:https://stackoverflow.com/questions/4427487/java-unknown-host-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!