2012-11-07 66 views
0

我的應用程序的一部分出現問題,有一種情況是我在json流上使用http請求來獲取一些數據,並且它工作得很好。但在另一種情況下,我必須使用用戶的位置來獲取數據。並在使用位置提供程序後,http請求無法正常工作。 這個問題只出現在兩個設備中的一個上,我必須測試我的應用程序。在第一個,Android 2.3.6的智能手機,我沒有問題。但是在第二臺設備上,問題出現在這裏:星系標籤與Android 4.0.4(我做了最近的更新,它是3.0.1之前,問題是相同的)。和我的應用程序編譯與SDK 10(Android 2.3.3)http請求在使用gps後無法正常工作

我試圖捕捉異常是拋出錯誤時出現,但異常的消息爲空,我不能看到是什麼問題。 的anibody尚未遇到這種錯誤?

private Runnable doRechercheGeoloc = new Runnable(){ 

    public void run() { 
     // TODO Auto-generated method stub 
     getProvider = true; 

     LocationListener locationListener = new LocationListener(){ 
      public void onLocationChanged(Location newLocation) { 
       // TODO Auto-generated method stub 
       Log.i("*", "GPS : location changed"); 
       location = newLocation; 
      } 

      public void onProviderDisabled(String provider) { 
       // TODO Auto-generated method stub 
       Log.i("*", "GPS : provider disabled"); 
      } 

      public void onProviderEnabled(String provider) { 
       // TODO Auto-generated method stub 
       Log.i("*", "GPS : provider enable"); 
      } 

      public void onStatusChanged(String provider, int status, 
        Bundle extras) { 
       // TODO Auto-generated method stub 
       Log.i("*", "GPS : status changed"); 
      } 
     }; 

     lm = (LocationManager) getSystemService(AnnuaireActivity.LOCATION_SERVICE); 
     Log.i("*", "le GPS est activé"); 
     lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 
     location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     lm.removeUpdates(locationListener); 
     lm = null; 
     getProvider = true; 
     lm = null; 

     handler.postAtFrontOfQueue(doRecherchePourGeoloc); 

    } 

}; 

和我的JSON解析器在那裏我做的HTTP連接的代碼:

public class JsonParser { 

... 

private String getJson(String url) throws Exception{ 

    StringBuilder builder = new StringBuilder(); 
    HttpClient client = new DefaultHttpClient(); 
    HttpGet get = new HttpGet(url); 

    try{ 

        //this is this instruction that provoque the error 
     HttpResponse response = client.execute(get); 
     StatusLine statusline = response.getStatusLine(); 
     int statuscode = statusline.getStatusCode(); 

     if (statuscode == 200){ 
      HttpEntity entity = response.getEntity(); 
      InputStream content = entity.getContent(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(content)); 
      String line; 
      while((line = reader.readLine()) != null){ 
       builder.append(line); 
      } 
     }else{ 
      Log.e("*", JsonParser.class.toString() + " : Failed to download file"); 
      throw new Exception(JsonParser.class.toString() + " : Failed to download file"); 
     } 

    }catch(ClientProtocolException e){ 
     Log.e("*", "JsonParser.getJson() : ClientProtocolException : " + e.getMessage()); 
     throw e;// 
    }catch(IOException ioe){ 
     Log.e("*", "JsonParser.getJson() : IOException : " + ioe.getMessage()); 
     throw ioe;// 
    }catch(Exception e){ 
     Log.e("*", "JsonParser.getJson() : Exception : " + e.getMessage());//the erreur is throwing from here and the message is null 
     throw e; 
    } 

    return builder.toString(); 
} 

... 

這裏是從活動的源代碼,可運行doRechercheGeoloc從上點擊一個按鈕啓動

}

thx。

+0

不要把標籤科目。我非常懷疑任何人都會通過所有這些代碼。那麼剝離所有不相關的部分呢? –

+0

我刪除了一些無用的代碼部分 – seb

回答

-1

logging

您正在使用什麼HTTP包/罐

?找出如何打開WIRE和HEADERS的日誌記錄。

我使用的軟件包,我必須在運行時重新編譯/使用單獨的http jar來獲取日誌記錄。

有了完整的日誌功能,你應該有足夠的數據來找到您的問題

看到亞行logcat樣品電線頭:

D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(18636): Attempt 1 to execute request 
D/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(18636): Sending request: POST /1/files/audio HTTP/1.1 
D/ch.boye.httpclientandroidlib.wire(18636): >> "POST /1/files/audio HTTP/1.1[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "X-Parse-Application-Id: 3KxPBTPSTe8f0iexGanSagCztLp6wSPzJkyMLAbR[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "X-Parse-REST-API-Key: kVl5Z0CXmBSCoQRmE8XSLIDFuLGHMCIkLXXjkuI9[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Type: audio/*[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Length: 12074[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Host: api.parse.com[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Connection: Keep-Alive[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]" 
D/ch.boye.httpclientandroidlib.headers(18636): >> POST /1/files/audio HTTP/1.1 
D/ch.boye.httpclientandroidlib.headers(18636): >> X-Parse-Application-Id: 3KxPBTPSTe8f0iexGanSagCztLp6wSPzJkyMLAbR 
D/ch.boye.httpclientandroidlib.headers(18636): >> X-Parse-REST-API-Key: kVl5Z0CXmBSCoQRmE8XSLIDFuLGHMCIkLXXjkuI9 
D/ch.boye.httpclientandroidlib.headers(18636): >> Content-Type: audio/* 
D/ch.boye.httpclientandroidlib.headers(18636): >> Content-Length: 12074 
D/ch.boye.httpclientandroidlib.headers(18636): >> Host: api.parse.com 
D/ch.boye.httpclientandroidlib.headers(18636): >> Connection: Keep-Alive 
D/ch.boye.httpclientandroidlib.wire(18636): >> "--" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "cVxX6b-jxQnxFCczaKHLNZ_Hq8HI9AEW219GW3w" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Disposition" 
D/ch.boye.httpclientandroidlib.wire(18636): >> ": " 
D/ch.boye.httpclientandroidlib.wire(18636): >> "form-data; name="bin"; filename="myfile.3gp"" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Type" 
D/ch.boye.httpclientandroidlib.wire(18636): >> ": " 
D/ch.boye.httpclientandroidlib.wire(18636): >> "application/octet-stream" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]" 
D/dalvikvm(18636): GC_CONCURRENT freed 387K, 5% free 11211K/11719K, paused 12ms+3ms, total 38ms 
D/dalvikvm(18636): WAIT_FOR_CONCURRENT_GC blocked 12ms 
D/ch.boye.httpclientandroidlib.wire(18636): >> "[0x0][0x0][0x0][0x18]ftyp3gp4[0x0][0x0][0x0][0x0]isom3gp4[0x0][0x0][0x2][0xe7]moov[0 
+0

我正在使用「org.apache.http」 – seb

+0

我在哪裏把這行代碼放在我的代碼中:java.util.logging.Logger.getLogger(「org.apache.http」) .setLevel(java.util.logging.Level.FINEST); – seb

+0

我是否在啓動應用程序 – seb