Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my app crash when my server is not connected?
    primarykey
    data
    text
    <p>I send some parameters to my server with httpGet or httpPost and it works fine when my client is connected to my server. But when it's not, my app crash. However, I have a try/catch...</p> <p>Look at my code:</p> <pre><code> ((ImageButton)findViewById(R.id.pickSurnom)).setOnClickListener(new OnClickListener(){ public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(Postit.this); alert.setTitle("Modifier votre surnom"); //alert.setMessage("Message"); // Set an EditText view to get user input final EditText input = new EditText(Postit.this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String surnom = input.getText().toString(); //Recuperation "id" du user dans les préférences partagées SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); String id = prefs.getString("id", null); //------------------------ENVOI---------------------------- StringBuffer stringBuffer = new StringBuffer(""); BufferedReader bufferedReader = null; try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(); //httpGet.setURI(new URI("http://192.168.0.1:8888/user/public"+"?"+"surnom="+((TextView) findViewById(R.id.surnom)).getText().toString())); httpGet.setURI(new URI("http://192.168.0.1:8888/user"+"?"+"id="+id+"surnom="+ surnom )); HttpResponse httpResponse = httpClient.execute(httpGet); bufferedReader = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); String ligneLue = bufferedReader.readLine(); Toast.makeText(getApplicationContext(), "id="+bufferedReader.readLine() , Toast.LENGTH_LONG).show(); while (ligneLue!=null){ stringBuffer.append(ligneLue); ligneLue = bufferedReader.readLine(); //Si la réponse = True //Remplir le bon surnom dans le TextView ((TextView) findViewById(R.id.surnom)).setText(surnom); } } catch (Exception e){ Toast.makeText(getApplicationContext(), "Connection error", Toast.LENGTH_LONG).show(); Log.e("Exception1", e.getMessage()); } finally { if (bufferedReader !=null){ try{ bufferedReader.close(); Toast.makeText(getApplicationContext(), "Serveur indisponible" + surnom, Toast.LENGTH_LONG).show(); } catch (IOException e){ Log.e("Exception2", e.getMessage()); } } } Log.i("Exception3", stringBuffer.toString()); </code></pre> <p>My LogCat</p> <pre><code>01-17 15:45:00.801: ERROR/ActivityManager(58): ANR in com.branchu1 (com.branchu1/.Postit) 01-17 15:45:00.801: ERROR/ActivityManager(58): Reason: keyDispatchingTimedOut 01-17 15:45:00.801: ERROR/ActivityManager(58): Load: 0.5 / 0.18 / 0.08 01-17 15:45:00.801: ERROR/ActivityManager(58): CPU usage from 32503ms to 56ms ago: 01-17 15:45:00.801: ERROR/ActivityManager(58): system_server: 19% = 15% user + 3% kernel / faults: 2075 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): ndroid.launcher: 3% = 2% user + 0% kernel / faults: 1554 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): adbd: 1% = 0% user + 0% kernel 01-17 15:45:00.801: ERROR/ActivityManager(58): ndroid.settings: 0% = 0% user + 0% kernel / faults: 124 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): m.android.phone: 0% = 0% user + 0% kernel / faults: 56 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 43 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): logcat: 0% = 0% user + 0% kernel / faults: 1 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): events/0: 0% = 0% user + 0% kernel 01-17 15:45:00.801: ERROR/ActivityManager(58): android.protips: 0% = 0% user + 0% kernel / faults: 23 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): zygote: 0% = 0% user + 0% kernel / faults: 135 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): .quicksearchbox: 0% = 0% user + 0% kernel / faults: 27 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): id.defcontainer: 0% = 0% user + 0% kernel / faults: 24 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): com.android.mms: 0% = 0% user + 0% kernel / faults: 25 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): m.android.music: 0% = 0% user + 0% kernel / faults: 23 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): d.process.media: 0% = 0% user + 0% kernel / faults: 25 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): m.android.email: 0% = 0% user + 0% kernel / faults: 34 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): com.svox.pico: 0% = 0% user + 0% kernel / faults: 23 minor 01-17 15:45:00.801: ERROR/ActivityManager(58): +com.branchu1: 0% = 0% user + 0% kernel 01-17 15:45:00.801: ERROR/ActivityManager(58): -com.branchu1: 0% = 0% user + 0% kernel 01-17 15:45:00.801: ERROR/ActivityManager(58): TOTAL: 33% = 25% user + 8% kernel + 0% softirq </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload