Force close startup when using AsyncTask
<p>i have a force close when trying following steps.</p>

<ol>
<li>Run app at the first time</li>
<li>play music</li>
<li>press home button and kill the app via app manager</li>
<li>run app again and the force close occurs</li>
</ol>

<p>this is my code :</p>

<pre><code>    private class LoadingFile extends AsyncTask&lt;Void, Integer, Void&gt; 
     {
     private ProgressDialog dialog = new ProgressDialog(BridgePlayer.this);
     protected void onPreExecute()
     {
         super.onPreExecute();
         if(isCancelled()) return;

         dialog.setMessage("Loading...");
         dialog.show();
     }

     protected Void doInBackground(Void... params) 
     {
         try
         {
             if(isCancelled()) return null;
             preInitialize();
             return null;
         }
         catch(Exception e) { return null; }
     }

     @Override
     protected void onProgressUpdate(Integer... progress) 
     {
         super.onProgressUpdate(progress);
         /*if(SONG_PATHS.size() &gt; 0)
         {
             dialog.setMessage(String.valueOf(progress[0]));
             dialog.show();
         }*/
     }

     protected void onPostExecute(Void result) 
     {
        super.onPostExecute(result);

        try
        {
        if(isCancelled()) return;
        if(dialog.isShowing()) 
        {
            dialog.dismiss();
        }

        initialize();

        this.cancel(true);
        }
        catch(Exception e) {  }
     }
}

    protected void onResume()
    {
    super.onResume();

    mSensorManager.registerListener(mSensorListener,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_UI);

    String date = String.valueOf(Calendar.getInstance().get(Calendar.DAY_OF_MONTH))+"-"+String.valueOf(Calendar.getInstance().get(Calendar.MONTH));

    blackList.clear();
    blackList.addAll(blackListToArray(sharedPrefs.getString("black_list", "")));

    loadFile = new LoadingFile();
    loadFile.execute();
}



    private void initialize()
    {       
    registerForContextMenu(songList);
    songList.setFastScrollEnabled(true);

    updateSongList("");

    if(SONG_PATHS.contains(sharedPrefs.getString("lastSongPath", "")) &amp;&amp; sharedPrefs.getString("lastSongPath", "")!="")
    {
        currentPosition = SONG_PATHS.indexOf(sharedPrefs.getString("lastSongPath", ""));
    }
    else currentPosition=0;

    if(sharedPrefs.getBoolean("isPause", true))
    {
        if(SONG_PATHS.size()&gt;0 &amp;&amp; SONG_PATHS.contains(sharedPrefs.getString("lastSongPath", "")))
        {
            try 
            {
                    mp.reset();
                    mp.setDataSource(SONG_PATHS.get(currentPosition));
                    mp.prepare();
                    mp.start();
                    sharedPrefs.edit().putString("lastSongPath", SONG_PATHS.get(currentPosition));
                    sharedPrefs.edit().putString("lastSongName", SONG_NAMES.get(currentPosition));
            } 
            catch (IllegalArgumentException e) {} 
            catch (IllegalStateException e) {e.printStackTrace();} 
            catch (IOException e) {e.printStackTrace();}

            mp.pause();
            mp.seekTo(sharedPrefs.getInt("currentDuration", 0));
            seekbar.setProgress(mp.getCurrentPosition()*1000/mp.getDuration());
        }
        pauseButton.setAlpha(128);
        playButton.setAlpha(255);
    }
    else
    {
        playButton.setAlpha(128);
        pauseButton.setAlpha(255);
    }

    songList.setSelection(currentPosition);

    int color;
    if(sharedPrefs.getString("list_background_color", "#000088").contains("Random"))
    {
        String[] colorArray = getResources().getStringArray(R.array.colorvalue);
        String colorString = colorArray[(int) (Math.random()*colorArray.length-1)];
        color = Color.parseColor(colorString);
    }
    else
    {
        color = Color.parseColor(sharedPrefs.getString("list_background_color", "#000088"));
    }
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[] {0xFF000000,color});
    songList.getRootView().setBackgroundDrawable(gradientDrawable);
    //songList.setBackgroundResource(R.drawable.kartini);
    //songList.getBackground().setAlpha(128);
    //ImageView iv = (ImageView)findViewById(R.id.background);
    //iv.setAlpha(100);

    Rect bounds = seekbar.getProgressDrawable().getBounds();
    seekbar.setProgressDrawable(new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[] {0x11FFFFFF,0xAAFFFFFF,0x11FFFFFF}));
    seekbar.getProgressDrawable().setBounds(bounds);
}

private void preInitialize()
{
    if(!(new File(MEDIA_PATH).exists())) (new File(MEDIA_PATH)).mkdirs(); 
    if(MEDIA_PATH!=sharedPrefs.getString("music_directory",MEDIA_PATH) || !(new File(getExternalCacheDir().getPath()+"nameFile.txt").exists()))
    {
        if((new File(sharedPrefs.getString("music_directory",MEDIA_PATH)).exists()))
        {
            MEDIA_PATH=sharedPrefs.getString("music_directory",MEDIA_PATH);
            createSongFile();
        }
    }

    scanDir();
}
</code></pre>

<p>this error only appear when i use asynctask. is there any clue for this error? i am so frustated after thinking for 8 hours. 
sorry for my english.</p>

<p>this is the log :</p>

<p>03-10 23:17:09.462: ERROR/AndroidRuntime(14363): FATAL EXCEPTION: main
03-10 23:17:09.462: ERROR/AndroidRuntime(14363): java.lang.RuntimeException: Unable to start activity ComponentInfo{bridge.entertainment/bridge.entertainment.BridgePlayer}: java.lang.NullPointerException
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.os.Looper.loop(Looper.java:123)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread.main(ActivityThread.java:3683)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at java.lang.reflect.Method.invokeNative(Native Method)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at java.lang.reflect.Method.invoke(Method.java:507)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at dalvik.system.NativeStart.main(Native Method)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363): Caused by: java.lang.NullPointerException
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at bridge.entertainment.BridgePlayer.updateSongList(BridgePlayer.java:105)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at bridge.entertainment.BridgePlayer.onCreate(BridgePlayer.java:43)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-10 23:17:09.462: ERROR/AndroidRuntime(14363):     ... 11 more</p>
