title: Android doInBackground Fatal expection Asynctask #1
body: <p>My app crashes after I try to work in the background with json. I don't know why it doesn't work.</p>
  
  <p>Class:</p>
  
  <pre><code>  package com.example.olda.hledac;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    import android.app.ListActivity;
  
    import org.apache.http.NameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
  
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
  
  
    public class vypis extends ListActivity {
  
  private ProgressDialog pDialog;
  
  JSONParser jParser = new JSONParser();
  
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; uzivatele;
  
  
  private static String url = "http://lokace.4fan.cz/vypis_uzivatelu.php";
  
  private static final String TAG_SUCCESS = "success";
  private static final String TAG_WP_USERS = "wp_users";
  private static final String TAG_ID = "ID";
  private static final String TAG_USER_login = "user_login";
  
  JSONArray uziv = null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_vypis);
      ListView lv = getListView();
      uzivatele = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          new VypisUzivatele().execute();
  
  
          lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  String ID = ((TextView) view.findViewById(R.id.ID)).getText()
                          .toString();
  
                  Intent in = new Intent(getApplicationContext(),
                          MenuActivity.class);
                  in.putExtra(TAG_ID, ID);
                  startActivityForResult(in, 100);
              }
          });
  
      }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == 100) {
          Intent intent = getIntent();
          finish();
          startActivity(intent);
      }
  
  }
  
   class VypisUzivatele extends AsyncTask&lt;String, String, String&gt; {
  
     @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(vypis.this);
          pDialog.setMessage("vypisování uživatelů");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
  
  
       protected String doInBackground(String... args) {
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          JSONObject json = jParser.makeHttpRequest(url, "GET", params);
           Log.d("All Products: ", json.toString());
  
           try {
              int success = json.getInt(TAG_SUCCESS);
  
              if (success == 1) {
                  uziv = json.getJSONArray(TAG_WP_USERS);
  
                  for (int i = 0; i &lt; uziv.length(); i++) {
                      JSONObject c = uziv.getJSONObject(i);
  
                      String id = c.getString(TAG_ID);
                      String name = c.getString(TAG_USER_login);
  
  
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
  
                      map.put(TAG_ID, id);
                      map.put(TAG_USER_login, name);
  
  
                      uzivatele.add(map);
                  }
              } else {
  
                  Intent i = new Intent(getApplicationContext(),
                          MenuActivity.class);
  
                  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(i);
              }
          } catch (JSONException e) {
              e.printStackTrace();
  
          }
  
          return null;
      }
  
  
      protected void onPostExecute(String file_url) {
          pDialog.dismiss();
  
          runOnUiThread(new Runnable() {
              public void run() {
  
                  ListAdapter adapter = new SimpleAdapter(
                          vypis.this, uzivatele,
                          R.layout.activity_uzivatele, new String[] { TAG_ID,
                          TAG_USER_login},
                          new int[] { R.id.ID, R.id.name });
                  setListAdapter(adapter);
              }
          });
  
      }
  
  }
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>    03-30 15:56:42.056    3999-4353/com.example.olda.hledac E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
      Process: com.example.olda.hledac, PID: 3999
      java.lang.RuntimeException: An error occured while executing doInBackground()
              at android.os.AsyncTask$3.done(AsyncTask.java:300)
              at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
              at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
              at java.util.concurrent.FutureTask.run(FutureTask.java:242)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:841)
       Caused by: java.lang.NullPointerException
              at com.example.olda.hledac.vypis$VypisUzivatele.doInBackground(vypis.java:98)
              at com.example.olda.hledac.vypis$VypisUzivatele.doInBackground(vypis.java:82)
              at android.os.AsyncTask$2.call(AsyncTask.java:288)
              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:841)
  03-30 15:56:42.696    3999-3999/com.example.olda.hledac E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.olda.hledac.vypis has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41baf8f8 V.E..... R......D 0,0-684,192} that was originally added here
              at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:370)
              at      android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
              at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
              at android.app.Dialog.show(Dialog.java:286)
              at com.example.olda.hledac.vypis$VypisUzivatele.onPreExecute(vypis.java:91)
              at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
              at android.os.AsyncTask.execute(AsyncTask.java:535)
              at com.example.olda.hledac.vypis.onCreate(vypis.java:51)
              at android.app.Activity.performCreate(Activity.java:5395)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
              at android.app.ActivityThread.access$800(ActivityThread.java:138)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5072)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>