2014-03-03 48 views
0

這現在已經到了我無法忍受的地步!我看到很多人都遇到同樣的問題,但他們的解決方案並不適合我。Android調用REST服務。未找到資源

我想從我的Android應用程序調用REST服務。我對Android的BTW還是個新手。 調用代碼看起來是這樣的:

String httpResult = ""; 
HttpClient httpClient = new DefaulthttpClient(); 
HttpContext httpContext = new BasicHttpContext(); 
String url = myURL; 
HttpGet httpGet = new HttpGet(myURL); 
HttpResponse response = httpClient.execute(httpGet, httpContext); 

//receive response in input stream 
InputStream is = response.getEntity().getContent(); 
//convert the stream into a string 
if(is != null){ 
//call method that will convert stream to string 
    httpResult = cString(is); 
}else{ 
    httpResult = "Error"; 
} 

當我調試的代碼,我看到當編譯器碰到"HttpClient httpClient = new DefaultHttpClient()"行代碼,並顯示"No Source Found"屏幕拋出異常。

+0

什麼是例外? – mach

+1

您是否在manifest.xml中設置了Internet權限? – Unii

+0

<使用權限android:name =「android.permission.INTERNET」/>在清單中,在附近標記 –

回答

1

當您調試沒有源文件的類時發生「找不到源」。

您應該在調試時使用F6來逐步完成。

+0

好吧,那麼我在哪裏找到類「org.apache.http.impl.client.DefaultHttpClient」源文件,因爲我覺得這是什麼不能解決 – Tumelo

+0

獲取了Android SDK源並導入到日食。你可以通過Android SDK Manager獲得它(找到正確的版本並選擇「Android SDK的源代碼」項) – tianwei

+0

我用F6來翻遍代碼,結果證明是XML編碼器給我的問題。所以我只是改變了我的REST服務來返回JSON,現在所有的工作都很好! yeeeeeeeepi! :) – Tumelo