title: Android - ASyncTask Error ThreadPoolExecutor
body: <p>I'm trying to download files in the background. I didn't change anything having to do with the file downloading or the asynctask, and all of a sudden it no longer worked. Here's my LogCat:</p>
  
  <pre><code>    03-04 17:51:45.485: W/System.err(1481): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
      03-04 17:51:45.485: W/System.err(1481):     at libcore.io.Posix.open(Native Method)
       03-04 17:51:45.485: W/System.err(1481):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
       03-04 17:51:45.485: W/System.err(1481):    at libcore.io.IoBridge.open(IoBridge.java:393)
       03-04 17:51:45.485: W/System.err(1481):    ... 14 more
       03-04 17:51:45.765: W/dalvikvm(1481): threadid=11: thread exiting with uncaught exception (group=0xb4af3b90)
       03-04 17:51:45.865: E/AndroidRuntime(1481): FATAL EXCEPTION: AsyncTask #1
       03-04 17:51:45.865: E/AndroidRuntime(1481): Process: com.csc.android.industryforum, PID: 1481
       03-04 17:51:45.865: E/AndroidRuntime(1481): java.lang.RuntimeException: An error occured while executing doInBackground()
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.lang.Thread.run(Thread.java:841)
       03-04 17:51:45.865: E/AndroidRuntime(1481): Caused by: java.lang.NullPointerException: lock == null
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.io.Reader.&lt;init&gt;(Reader.java:64)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.io.InputStreamReader.&lt;init&gt;(InputStreamReader.java:122)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.io.InputStreamReader.&lt;init&gt;(InputStreamReader.java:59)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at com.csc.android.industryforum.MainActivity.readFileArray(MainActivity.java:902)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at com.csc.android.industryforum.MainActivity.handleMenuInfo(MainActivity.java:355)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at com.csc.android.industryforum.MainActivity.access$1(MainActivity.java:342)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at com.csc.android.industryforum.MainActivity$DownloadTask.doInBackground(MainActivity.java:1023)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at com.csc.android.industryforum.MainActivity$DownloadTask.doInBackground(MainActivity.java:1)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       03-04 17:51:45.865: E/AndroidRuntime(1481):    ... 4 more
       03-04 17:51:46.485: I/Choreographer(1481): Skipped 72 frames!  The application may be doing too much work on its main thread.
       03-04 17:51:46.925: I/Choreographer(1481): Skipped 65 frames!  The application may be doing too much work on its main thread.
       03-04 17:51:48.615: E/WindowManager(1481): android.view.WindowLeaked: Activity com.csc.android.industryforum.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b4dcd940 V.E..... R.....ID 0,0-424,140} that was originally added here
       03-04 17:51:48.615: E/WindowManager(1481):     at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:346)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.Dialog.show(Dialog.java:286)
       03-04 17:51:48.615: E/WindowManager(1481):     at com.csc.android.industryforum.MainActivity.loadFiles(MainActivity.java:136)
       03-04 17:51:48.615: E/WindowManager(1481):     at com.csc.android.industryforum.MainActivity.onCreate(MainActivity.java:99)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.Activity.performCreate(Activity.java:5243)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.os.Handler.dispatchMessage(Handler.java:102)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.os.Looper.loop(Looper.java:137)
       03-04 17:51:48.615: E/WindowManager(1481):     at android.app.ActivityThread.main(ActivityThread.java:4998)
       03-04 17:51:48.615: E/WindowManager(1481):     at java.lang.reflect.Method.invokeNative(Native Method)
       03-04 17:51:48.615: E/WindowManager(1481):     at java.lang.reflect.Method.invoke(Method.java:515)
       03-04 17:51:48.615: E/WindowManager(1481):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
       03-04 17:51:48.615: E/WindowManager(1481):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
       03-04 17:51:48.615: E/WindowManager(1481):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>According to one of the answers, the problem is with my file reading, so here's the code:</p>
  
  <pre><code>private ArrayList&lt;String&gt; readFileArray(File file){
      FileInputStream in = null;
      try {
          in = openFileInput(file.getName());
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      InputStreamReader inputStreamReader = new InputStreamReader(in);//this is line 902
      BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
      StringBuilder sb = new StringBuilder(); 
      String line;
      String line1 = "";
      ArrayList&lt;String&gt; ar1 = new ArrayList&lt;String&gt;(); 
      try {
          while ((line = bufferedReader.readLine()) != null) {
              sb.append(line);
              ar1.add(line);
              if (line1.equals("")){
                  line1 = line1 + line;
              }else{
              line1 = line1 + "\n" + line;
              }
          }
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return ar1;
  
  }
  </code></pre>
  
  <p>And here's the code that calls that code:</p>
  
  <pre><code>    private String[] handleMenuInfo(String selection){
      DataClass dc = new DataClass(this);
  
      File dir = getDir("myDir", Context.MODE_PRIVATE);
      File file = new File(dir, selection + ".txt");
      ArrayList &lt;String&gt; menuArray;
  
          menuArray = readFileArray(file);
          String[] menuList = menuArray.toArray(new String[menuArray.size()]);
          return menuList;
      //}
  
  }
  </code></pre>
  
  <p>Here's the ASyncTask</p>
  
  <pre><code> private class DownloadTask extends AsyncTask&lt;Integer, Void, Void&gt; {
  
      private Context context;
      private PowerManager.WakeLock mWakeLock;
  
      public DownloadTask(Context context) {
          this.context = context;
      }
  
      @Override
      protected void onPreExecute() {
  
      }
  
       protected void onPostExecute() {
  
      }
  
      @Override
      protected Void doInBackground(Integer... sUrl) {
  
              DataClass dc = new DataClass(c);
              //ArrayList&lt;String&gt; menuArray = dc.getMenuArray("Home");
              String[] menuArray = {"Home", "Announcements", "Speakers", "Events", "Exhibitors", "Agenda", "Hotels", "Documents"}; 
              File dir = getDir("myDir", Context.MODE_PRIVATE);
  
              for(int i=1; i &lt;= 7; i++){
                  String[] menuList = handleMenuInfo(menuArray[i]);
                  mProgressDialog.setIndeterminate(false);
                  mProgressDialog.setMax(7);
                  mProgressDialog.setProgress(i);
                  for(int i2=1; i2 &lt; menuList.length; i2++){
                  File file = new File(dir, menuArray[i]  + "/" + menuList[i2] + ".txt");
                  ArrayList&lt;String&gt; viewArray = dc.getInfoArray(menuArray[i],menuList[i2]);
                  writeToFile(file, viewArray);
  
                  }
              }
              SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
              Editor editor = sharedPreferences.edit();
              editor.putString("new", "No");
              editor.commit();
              mProgressDialog.dismiss();
         return null;
  
  
          }
      }
  
  
  }
  </code></pre>