Android Jellybean Failed JSON Download on HttpUrlConnection
<p>I am trying to download json data for an android application using the JELLYBEAN API 17.</p>

<p>I have added the uses permission for the internet within the manifest file also.</p>

<p>This is the code for getting the json data within the activity:</p>

<pre><code>   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //final Button btnLoad = (Button) findViewById(R.id.btnLoad);
    tvResult = (TextView) findViewById(R.id.txtView);
    //

}

   public void onClick(View v) {
    final LoadData data = new LoadData();
        Log.d("TAG","Button Pressed!");


                data.execute();
                tvResult.setText(data.get());


    }

public static  String getJSON(String url) throws IOException {
    URL u = new URL(url);
    HttpURLConnection c = (HttpURLConnection) u.openConnection();
    try {
        c.setRequestMethod("GET");
        c.setRequestProperty("Content-length", "0");
        c.setUseCaches(false);
        c.setAllowUserInteraction(false);

        c.connect();
        //int status = c.getResponseCode();


            BufferedReader br = new BufferedReader(new InputStreamReader(
                    c.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line ="";
            while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
            br.close();
            return sb.toString();


    }finally{
    c.disconnect();
    }
}
// Inner class for making an asyncTask
public class LoadData extends AsyncTask&lt;Void, Void, String&gt; {

    @Override
    protected String doInBackground(Void... params) {
        final TMDb tmdb = new TMDb();
        String data = "";
        try {
             data = getJSON("http://api.themoviedb.org/3/genre/list?api_key=#");                
         tvResult.setText(data);

          Log.d("TAG-DATA", data);
          Log.d("TAG", "RUN STARTED!");

        } catch (IOException e) {
            Log.d("ERROR", e.getMessage());
            e.printStackTrace();
        }
        return data;
    }

}
</code></pre>

<p>This works fine for a regular java application. But within an android application tends to kill the activity. It produced the following errors:</p>

<pre><code>D/TAG(13771): Button Pressed!
W/dalvikvm(13771): threadid=11: thread exiting with uncaught exception (group=0x40bce930)
 E/AndroidRuntime(13771): FATAL EXCEPTION: Thread-6603
 E/AndroidRuntime(13771): java.lang.NullPointerException: println needs a message
 E/AndroidRuntime(13771):   at android.util.Log.println_native(Native Method)
 E/AndroidRuntime(13771):   at android.util.Log.d(Log.java:138)
 E/AndroidRuntime(13771):   at com.mjavacam.tmdb.MainActivity$1.run(MainActivity.java:88)
 E/AndroidRuntime(13771):   at java.lang.Thread.run(Thread.java:856)
</code></pre>

<p>Can anyone assist by showing me in the following:</p>

<ul>
<li><p>how to properly make a http request from an android application?</p></li>
<li><p>identify what I might be doing wrong?</p></li>
</ul>
