i have a problem with a part of my application, in one case i use http request on a json stream to get some data, and it work really good. but in another case, i have to use the location of the user to get the data. and after using the location provider, http request didn't work correctly. this problem appear only on one of the two device i have to test my application. on the first one, a smart phone with android 2.3.6, i have no problem. but that is on the seconde device, where the problem appear: a galaxy tab with android 4.0.4 (i have do a recent update of it, it was 3.0.1 before, problem was the same). and my application is compiled with the sdk 10 (android 2.3.3)
i try to catch the exception that is throw when the bug appear, but the message of the exception is null and i cant see what is the problem. does anibody have yet encounter this sort of bug ?
here is the source code from the activity, the runnable doRechercheGeoloc is launched from a click on a button :
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);
}
};
and the code of my json parser where i do the http connection :
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();
}
...
}
thx.