title: WindowLeak error in Android
body: <p>I am currently working on a Android project and I have ran into one particular error. The error I'm having is a window leak error. I only thing I can think of that is causing this problem is my layouts for my project or if it was ListView Actvity but I'm really not sure because I have never seen this error before. So I was just hoping if somebody could tell me what is causing this error and what I can do to fix it. </p>
  
  <pre><code>07-29 13:43:59.891: E/WindowManager(952): Activity com.theproblemsolver.ListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d0f620 V.E..... R.....ID 0,0-234,72} that was originally added here
  07-29 13:43:59.891: E/WindowManager(952): android.view.WindowLeaked: Activity com.theproblemsolver.ListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d0f620 V.E..... R.....ID 0,0-234,72} that was originally added here
  07-29 13:43:59.891: E/WindowManager(952):   at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:354)
  07-29 13:43:59.891: E/WindowManager(952):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
  07-29 13:43:59.891: E/WindowManager(952):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.Dialog.show(Dialog.java:281)
  07-29 13:43:59.891: E/WindowManager(952):   at com.theproblemsolver.ListView$LoadAllData.onPreExecute(ListView.java:86)
  07-29 13:43:59.891: E/WindowManager(952):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
  07-29 13:43:59.891: E/WindowManager(952):   at android.os.AsyncTask.execute(AsyncTask.java:534)
  07-29 13:43:59.891: E/WindowManager(952):   at com.theproblemsolver.ListView.onCreate(ListView.java:52)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.Activity.performCreate(Activity.java:5104)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  07-29 13:43:59.891: E/WindowManager(952):   at android.os.Handler.dispatchMessage(Handler.java:99)
  07-29 13:43:59.891: E/WindowManager(952):   at android.os.Looper.loop(Looper.java:137)
  07-29 13:43:59.891: E/WindowManager(952):   at android.app.ActivityThread.main(ActivityThread.java:5041)
  07-29 13:43:59.891: E/WindowManager(952):   at java.lang.reflect.Method.invokeNative(Native Method)
  07-29 13:43:59.891: E/WindowManager(952):   at java.lang.reflect.Method.invoke(Method.java:511)
  07-29 13:43:59.891: E/WindowManager(952):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  07-29 13:43:59.891: E/WindowManager(952):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  07-29 13:43:59.891: E/WindowManager(952):   at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>ListView:</p>
  
  <pre><code>public class ListView extends ListActivity {
  
      private ProgressDialog pDialog;
  
      JSONParsser jParser = new JSONParsser();
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; questionList;
  
      private static String URI = "http://example.com/json";;
  
      //JSONObject json = jParser.getJSONFromURI(URI);
  
       final String TAG_QUESTION_SUBJECT = "Subject";
       final String TAG_QUESTION_NUMANSWERS = "NumAnswers";
       final String TAG_QUESTION = "Question";
       final String TAG_QUESTION_CONTENT = "Content";
       final String TAG_QUESTION_CHOSENANSWER = "ChosenAnswer";
       final String TAG_ANSWERS = "Answers";
       final String TAG_ANSWER = "Answer";    
  
              JSONArray Question = null;
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState); 
          //setContentView(R.layout.listview);
  
      //questionList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      android.widget.ListView lv = getListView(); 
  
      new LoadAllData().execute();
  
      lv.setOnItemClickListener(new OnItemClickListener() {
  
      @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,int position, long id) {
  
  
          }
      });
  
  }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (resultCode == 100) {
              Intent intent = getIntent();
              startActivity(intent);
              finish();
          }
      }
  
      class LoadAllData extends AsyncTask&lt;String, String, String&gt; {
  
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(ListView.this);
              pDialog.setMessage("Loading Data. Please wait...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              pDialog.show();
              //JSONParsser jParser = new JSONParsser();
          }
  
          protected String doInBackground(String... args) {
  
              JSONObject json = jParser.getJSONFromURI(URI);
  
              try {
  
                      Question = json.getJSONArray(TAG_QUESTION);
  
                     for(int i = 0; i &lt; Question.length(); i++) {
                         JSONObject q = Question.getJSONObject(i);
  
                         String Subject = q.getString(TAG_QUESTION_SUBJECT);
                         String NumAnswers = q.getString(TAG_QUESTION_NUMANSWERS);
                         String ChosenAnswers = q.getString(TAG_QUESTION_CHOSENANSWER);
                         String Content = q.getString(TAG_QUESTION_CONTENT);
  
                         JSONObject Answers = q.getJSONObject(TAG_ANSWERS);
                         String Answer = Answers.getString(TAG_ANSWER);
  
                       questionList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
                         HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                         map.put(TAG_QUESTION_SUBJECT, Subject);
                         map.put(TAG_QUESTION_NUMANSWERS, NumAnswers);
  
                         questionList.add(map);
                     }
  
  
  
              } catch (JSONException e) {
                  e.printStackTrace();
              }
              return null;
  
  
          }
  
          @Override
          protected void onPostExecute(String file_URI) {
  
              if (pDialog != null &amp;&amp; pDialog.isShowing()) pDialog.dismiss();
              runOnUiThread(new Runnable() {
              public void run() {
                  ListAdapter adapter = new SimpleAdapter(getBaseContext(), questionList,
                          R.layout.row,
                          new String[] { TAG_QUESTION_SUBJECT, TAG_QUESTION_NUMANSWERS }, new int[] {
                          R.id.Subject, R.id.NumAnswers });
  
                  setListAdapter(adapter);
  
  
  
                  }
              });
  
          }
  }}
  </code></pre>
  
  <p>Row.xml Layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;TextView
          android:id="@+id/Subject"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
      &lt;TextView 
          android:id="@+id/NumAnswers"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>