title: Issues with AsycTask for json request
body: <pre><code>    package com.example.hstnc_activity;
  
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.Reader;
  import java.net.URL;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.app.ListActivity;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Build;
  import android.os.Bundle;
  import android.support.v4.app.NavUtils;
  import android.util.JsonReader;
  import android.view.MenuItem;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.widget.ArrayAdapter;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  
  
  public class DisplayServiceActivity extends ListActivity {
      private ListView listOfServices;
  
      //JSONArrays?
      JSONArray directory = null; 
  
      //JSON Node names
      private static String TAG_ID = "id";
      private static String TAG_NAME= "name";
      private static String TAG_DIRECTORY = "Categories";
      private final static String url;    
      JSONObject json;
      jsonParser jParser = new jsonParser();
  
      @SuppressLint("NewApi")
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          new Request().onPostExecute(url);
  
          listOfServices =getListView(); //get builtin listView
  
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; directoryList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          // Intent intent = getIntent();
          //String url = intent.getStringExtra("SERVICES_DIRECTORY");
  
  
          try{
              //getting Array
              directory = json.getJSONArray(TAG_DIRECTORY);
  
              for(int i= 0; i&lt;directory.length(); i++){
                  JSONObject addItem =directory.getJSONObject(i);
  
                  //store each item in variable 
                  String id = addItem.getString(TAG_ID);
                  String name= addItem.getString(TAG_NAME);
  
                  //create new HashMap
                  HashMap&lt;String,String&gt; map = new HashMap&lt;String, String&gt;();
  
                  //add each child node to HashMap key
                  map.put(TAG_ID, id);
                  map.put(TAG_NAME, name);
  
                  //adding HashList to ArrarList
                  directoryList.add(map);
              }
  
          } catch (JSONException e){
              e.printStackTrace();
          }
  
          ListAdapter adapter = new SimpleAdapter(this,
                  directoryList, 
                  R.layout.list_item, 
                  new String[] { TAG_ID,TAG_NAME }, 
                  new int[] { android.R.id.text1,android.R.id.text2 });
  
          setListAdapter(adapter);
          setContentView(R.layout.service);
          // Make sure we're running on Honeycomb or higher to use ActionBar APIs
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
              // Show the Up button in the action bar.
              getActionBar().setDisplayHomeAsUpEnabled(true);
          }
      }// end of onCreate Method
      @SuppressWarnings("unused")
      public class Request extends AsyncTask&lt;Void, Void, Void&gt; {
          protected Void doInBackground(Void... params) {
              json = jParser.getJSONfromURL(url);
              return null;
          }
           protected void onPostExecute(String url) {
               json = jParser.getJSONfromURL(url);
           }
  
      }
  
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
          case android.R.id.home:
              NavUtils.navigateUpFromSameTask(this);
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>I'm tyring to do a JSON request in Android and take the information and put it into a listview. I keep receiving "Error in HTTP connection android.os.NetworkOnMainThreadException" as an error when I debug. When running the apk it simply force closes when I open this activity. This activity is launched via a button on another screen.</p>