Note that there are some explanatory texts on larger screens.

plurals
  1. POapplication crashes if the server is closed due to timeout. How can I catch it?
    text
    copied!<pre><code> String urlStr = "nana.com/nana/api/v1" HttpURLConnection conn = null; BufferedReader rd = null; StringBuilder sb = null; try { URL url = new URL(urlStr); conn = (HttpURLConnection) url.openConnection(); if (conn.getResponseCode() != 200) { throw new IOException(conn.getResponseMessage()); } else { rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); conn.disconnect(); } } catch (IOException i) { i.printStackTrace(); }catch (Exception e) { e.printStackTrace(); </code></pre> <p>This code works for me if the server is active and working, but when I shut the server down it goes into timeout and crashes 'unexpectedly'. All I want is that the application to say or display a alertdialog if the server is unreachable. This is my logcat:</p> <pre><code> 09-14 11:52:57.702: E/AndroidRuntime(17256): at android.os.Handler.dispatchMessage(Handler.java:99) 09-14 11:52:57.702: E/AndroidRuntime(17256): at android.os.Looper.loop(Looper.java:130) 09-14 11:52:57.702: E/AndroidRuntime(17256): at android.app.ActivityThread.main(ActivityThread.java:3693) 09-14 11:52:57.702: E/AndroidRuntime(17256): at java.lang.reflect.Method.invokeNative(Native Method) 09-14 11:52:57.702: E/AndroidRuntime(17256): at java.lang.reflect.Method.invoke(Method.java:507) 09-14 11:52:57.702: E/AndroidRuntime(17256): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 09-14 11:52:57.702: E/AndroidRuntime(17256): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 09-14 11:52:57.702: E/AndroidRuntime(17256): at dalvik.system.NativeStart.main(Native Method) 09-14 11:52:57.742: E/(179): Dumpstate &gt; /data/log/dumpstate_app_error </code></pre>
 

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