2011-11-28 96 views
2

所以我有一個django服務器運行在我的本地機器上,我想通過我在仿真器中運行的android應用程序連接到。當我在Web瀏覽器中輸入這些信息時(我得到我期待的json對象),一切正常。但我的android代碼不起作用。無法連接到本地主機形式android模擬器

try { 
     HttpClient client = new DefaultHttpClient(); 
     HttpGet request = new HttpGet(); 
     request.setURI(new URI("http://10.0.2.2:8080/getUserInfo/" + username + "/")); 

     //next line throws exception 
     HttpResponse response = client.execute(request); 
     HttpEntity resEntity = response.getEntity(); 
     if (resEntity != null) { 
      Log.i("GET RESPONSE",EntityUtils.toString(resEntity)); 
      String jsonString = EntityUtils.toString(resEntity); 
      return jsonToAccount(jsonString); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return null; 

我試圖在localhost127.0.0.110.0.2.2底塗,我也嘗試過的,而不是8080 8000端口,任何人可以看到這個問題?

這裏是堆棧跟蹤:(如果你在新標籤中打開它,你可以閱讀)

enter image description here

+1

無。 但是你可以。請發佈堆棧跟蹤:) – MByD

+1

永遠不要在PC上設置服務器,並使用它來測試仿真器中的應用程序,但是:不會將'127.0.0.1'等引用到手機/仿真器中作爲本地主機這種情況下,而不是你試圖達到的主機? – 2011-11-28 20:40:35

+0

你在網頁瀏覽器中輸入什麼(完全)? – hovanessyan

回答

9

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

在您的Android清單

+17

我討厭自己.. – wbarksdale