【问题标题】:DEBUG/SntpClient(70): request time failed: java.net.SocketException: Address family not supported by protocol on AndroidDEBUG/SntpClient(70):请求时间失败:java.net.SocketException:Android 上的协议不支持地址族
【发布时间】:2011-07-03 08:23:39
【问题描述】:

我创建这样的代码:

try {
    int ct_id;
    String ct_name;
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/update.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    }catch(Exception e){
        Log.e("log_tag", "Error in http connection"+e.toString());
    }
    //convert response to string
    try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        sb = new StringBuilder();
        sb.append(reader.readLine() + "\n");
        String line="0";
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
    }catch(Exception e){
        Log.e("log_tag", "Error converting result "+e.toString());
    }
    //paring data
    int max = 0;
    try{
        jArray = new JSONArray(result);
        JSONObject json_data=null;
        for(int i=0;i<jArray.length();i++){
            json_data = jArray.getJSONObject(i);
            ct_id=json_data.getInt("max(id)");
            ct_name=json_data.getString("date");
            max = ct_id;
        }
    }
    catch(JSONException e1){

} catch (ParseException e1) {
    e1.printStackTrace();
}

但是当我调试时它出现了:

07-03 08:50:42.657: DEBUG/SntpClient(70): request time failed: java.net.SocketException: Address family not supported by protocol

这是什么意思?以及如何解决?

【问题讨论】:

    标签: java android network-programming android-networking


    【解决方案1】:

    这看起来像一个本地 url,你确定你的 apache 是在 80 端口上运行的吗?您可以尝试在桌面浏览器中访问此 url http://10.0.2.2/update.php 吗?这个错误一般只有在socket无法与服务器建立连接时才会出现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多