title: FATAL EXCEPTION: AsyncTask #1 in android
body: <p>May be this is duplicate question but I did not find any solutions.</p>
  
  <p>I want to get the file name from folder and display it using async but I get the following error  <code>FATAL EXCEPTION: AsyncTask #1 Error java.lang.RuntimeException: An error occured while executing doInBackground()</code>  </p>
  
  <p>Given below is my code</p>
  
  <pre><code> private static String[] listArr ;
   private static  String[] listArrview  ;
  
   private static final ArrayList&lt;String&gt; ary_user_pdf = new ArrayList&lt;String&gt;();
   private static final ArrayList&lt;String&gt; ary_user_pdfview = new ArrayList&lt;String&gt;();
  
   new AsyncAction().execute(null, null, null);
  </code></pre>
  
  <p><strong>filldata() function</strong></p>
  
  <pre><code>if(file.exists() &amp;&amp; file.listFiles().length&gt;0)
  {
      File list[] = file.listFiles();
      for( int i=0; i&lt; list.length; i++)
      {
          //myList.add( list[i].getName() );
          ary_user_pdf.add(list[i].getName());
          ary_user_pdfview.add(list[i].getName());
      }
  
      listArr = new String[ary_user_pdf.size()];
      listArr = ary_user_pdf.toArray(listArr);
      listArrview = new String[ary_user_pdfview.size()];
      listArrview = ary_user_pdfview.toArray(listArrview);
  }
  
  
  private class AsyncAction extends AsyncTask&lt;String, Void, String&gt; {
          public boolean status = false;
          private ProgressDialog pd;
  
          @Override
          protected String doInBackground(String... arg0) {
              // TODO Auto-generated method stub
              try {
  
                  fillData();
                  status = true;
  
              } catch (Exception e) {
                  // TODO: handle exception
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(String result) {
  
              pd.dismiss();
  
  
                  MyArrayAdapter adapter = new MyArrayAdapter(Downloadpdf.this,
                          listArr);
                  lstSub.setAdapter(adapter);
  
          }
  
          protected void onPreExecute() {
              // TODO Auto-generated method stub
              super.onPreExecute();
              pd = new ProgressDialog(Downloadpdf.this);
              pd.setTitle("PDF");
              pd.setMessage("Please wait while we are loading PDF.");
              pd.setIndeterminate(true);
              pd.setCancelable(false);
              pd.show();
          }
  </code></pre>
  
  <p><strong>LOG:</strong></p>
  
  <pre><code>10-10 13:05:19.791: E/AndroidRuntime(19301): FATAL EXCEPTION: AsyncTask #1
  10-10 13:05:19.791: E/AndroidRuntime(19301): java.lang.RuntimeException: An error occured while executing doInBackground()
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.lang.Thread.run(Thread.java:1019)
  10-10 13:05:19.791: E/AndroidRuntime(19301): Caused by: java.lang.NoSuchMethodError: android.os.Bundle.getString
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at com.paper.solution.Downloadpdf.fillData(Downloadpdf.java:162)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at com.paper.solution.Downloadpdf$AsyncAction.doInBackground(Downloadpdf.java:112)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at com.paper.solution.Downloadpdf$AsyncAction.doInBackground(Downloadpdf.java:1)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  10-10 13:05:19.791: E/AndroidRuntime(19301):    ... 4 more
  10-10 13:05:20.841: E/WindowManager(19301): Activity com.paper.solution.Downloadpdf has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052ee20 that was originally added here
  10-10 13:05:20.841: E/WindowManager(19301): android.view.WindowLeaked: Activity com.paper.solution.Downloadpdf has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052ee20 that was originally added here
  10-10 13:05:20.841: E/WindowManager(19301):     at android.view.ViewRoot.&lt;init&gt;(ViewRoot.java:258)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.Dialog.show(Dialog.java:241)
  10-10 13:05:20.841: E/WindowManager(19301):     at com.paper.solution.Downloadpdf$AsyncAction.onPreExecute(Downloadpdf.java:151)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.os.AsyncTask.execute(AsyncTask.java:391)
  10-10 13:05:20.841: E/WindowManager(19301):     at com.paper.solution.Downloadpdf.layout(Downloadpdf.java:98)
  10-10 13:05:20.841: E/WindowManager(19301):     at com.paper.solution.Downloadpdf.onCreate(Downloadpdf.java:71)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.os.Handler.dispatchMessage(Handler.java:99)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.os.Looper.loop(Looper.java:123)
  10-10 13:05:20.841: E/WindowManager(19301):     at android.app.ActivityThread.main(ActivityThread.java:3647)
  10-10 13:05:20.841: E/WindowManager(19301):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-10 13:05:20.841: E/WindowManager(19301):     at java.lang.reflect.Method.invoke(Method.java:507)
  10-10 13:05:20.841: E/WindowManager(19301):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  10-10 13:05:20.841: E/WindowManager(19301):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  10-10 13:05:20.841: E/WindowManager(19301):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>