2011-07-03 51 views
2

支持我創造這樣的代碼:DEBUG/SntpClient(70):請求時間失敗:java.net.SocketException異常:地址家族不受協議在Android

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 

這是什麼意思?以及如何解決它?

回答

0

這看起來像一個本地URL,你確定你的Apache是​​在端口80上運行?你可以嘗試在桌面瀏覽器中訪問這個網址http://10.0.2.2/update.php,你是否正確地看到了東西。這個錯誤通常只在套接字無法與服務器建立連接時纔會出現。

相關問題