title: BufferedRead runtime crash
body: <p>My app crash when encounters BufferedReader operation. Ive tried to implement the code inside an asyncTask classe, because ive read that the crash is caused by the ui thread, but nothing has changed.</p>
  
  <pre><code>public class URLConnectionReader extends AsyncTask&lt;URL, Void, String&gt; {
  
      String result = null;
  
      @Override
      protected String doInBackground(URL... params) {
  
          String result = null;
  
          URL url = (params[0]);
  
          try {
  
              BufferedReader reader = new BufferedReader(
                      new InputStreamReader(
                              url.openStream()
                      )
              );
  
          }catch (IOException e){
              e.printStackTrace();
          }
  
          return result;
  
      }
  }
  </code></pre>
  
  <p>Logs</p>
  
  <pre><code>03-02 13:28:43.215  25186-25186/com.example.jsonreader E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.example.jsonreader, PID: 25186
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsonreader/com.example.jsonreader.MainActivity}: android.os.NetworkOnMainThreadException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
       Caused by: android.os.NetworkOnMainThreadException
              at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
              at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
              at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
              at java.net.InetAddress.getAllByName(InetAddress.java:215)
              at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
              at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
              at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
              at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
              at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
              at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
              at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
              at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190)
              at java.net.URL.openStream(URL.java:470)
              at com.example.jsonreader.URLConnectionReader.doInBackground(URLConnectionReader.java:38)
              at com.example.jsonreader.MainActivity.onCreate(MainActivity.java:27)
              at android.app.Activity.performCreate(Activity.java:5933)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>MainActivity code</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          try {
              URL address = new URL("http://www.youth-stories.com/api/all.php");
              URLConnectionReader reader = new URLConnectionReader();
              String result = reader.doInBackground(address);
              Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
          }catch (IOException e){
              e.printStackTrace();
          }
  </code></pre>