简体   繁体   English

Java未知主机异常

[英]Java unknown host exception

I am trying to access textalertapp.com via HTTP Post request from my android application. 我试图通过我的Android应用程序的HTTP Post请求访问textalertapp.com。 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));
                }
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

I just added this line in manifest file. 我刚在清单文件中添加了这一行。 Problem solved 问题解决了

This means that your host is unknown, ie does not exist or is not accessible. 这意味着您的主机未知,即不存在或无法访问。 Check you IP again and check whether you can get this IP from your device. 再次检查IP并检查是否可以从您的设备获取此IP。 Probably this IP exists in your local network and is not accessible from outside. 这个IP可能存在于您的本地网络中,无法从外部访问。

If IP exists check firewall definitions. 如果IP存在,请检查防火墙定义 Firewall cause the same effect. 防火墙会产生同样的效果。

I just started receiving the "java.net.UnknownHostException" error when fetching content from a URL that previously worked perfectly. 我从刚刚完美运行的URL中获取内容时刚开始收到“java.net.UnknownHostException”错误。

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. 在圈了一段时间之后,我手动删除了我的项目的/ bin文件夹,并在Eclipse中清理了项目(Project - > Clean),修复了这个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM