method getInputStream() in HttpURLConnection in Android always failed
<pre><code>HttpURLConnection urlConn = (HttpURLConnection) new URL(
                "http://www.google.com").openConnection();

        InputStream is = urlConn.getInputStream();

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String inputLine = "";
        while ((inputLine = br.readLine()) != null) {
            result += inputLine;
        }
</code></pre>

<p>When it comes to urlConn.getInputStream(), it fails.
But the same code works in normal java project instead of Android project.</p>

<p>And I find that in Android, when it runs the first statement, urlConn is:"libcore.net.http.HttpURLConnectionImpl:http://www.google.com"</p>

<p>But in normal java project, it is "sun.net.www.protocol.http.HttpURLConnection:http://www.google.com"</p>

<p>Thanks!!</p>

<p>Exception stack:</p>

<pre><code>11-21 21:14:01.750: I/System.out(20784): debugger has settled (1392)
11-21 21:14:56.380: W/dalvikvm(20784): threadid=1: thread exiting with uncaught exception (group=0x410e49d8)
11-21 21:14:56.420: E/AndroidRuntime(20784): FATAL EXCEPTION: main
11-21 21:14:56.420: E/AndroidRuntime(20784): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.network/com.example.network.MainActivity}: android.os.NetworkOnMainThreadException
11-21 21:14:56.420: E/AndroidRuntime(20784):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1969)
11-21 21:14:56.420: E/AndroidRuntime(20784):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1994)
11-21 21:14:56.420: E/AndroidRuntime(20784):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
</code></pre>

<p>I have added the INTERNET permission.</p>
