开发者

onActivityResult crash "Failure delivering result"

I have a FileBrowser activity that I got from AndDev site. The problem is that it stopped working and it crashes, here is the logcat:

07-05 11:20:35.803: ERROR/AndroidRuntime(14706): FATAL EXCEPTION: main
07-05 11:20:35.803: ERROR/AndroidRuntime(14706): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {omar.quran1/omar.quran1.DataDownload}: java.lang.NullPointerException
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.os.Looper.loop(Looper.java:130)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread.main(ActivityThread.java:3687)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at java.lang.reflect.Method.invoke(Method.java:507)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at dalvik.system.NativeStart.main(Native Method)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706): Caused by: java.lang.NullPointerException
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at omar.quran1.DataDownload.dirSize(DataDownload.java:387)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at omar.quran1.DataDownload.CheckIfFilesAlreadyExist(DataDownload.java:372)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at omar.quran1.DataDownload.onActivityResult(DataDownload.java:310)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
07-05 11:20:35.803: ERROR/AndroidRuntime(14706):     ... 11 more

Here is what I do once the user chose the folder he wants:

         StatFs stat = new StatFs(currentDirectory.getAbsolutePath());
                stat.restat(currentDirectory.getAbsolutePath());
                long available = ((long) stat.getAvailableBlocks() * (long) stat.getBlockSize());


                if((available / 1048576)>120)
                {
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra("FilePath", currentDirectory.getPath());
                    setResult(Activity.RESULT_OK, resultIntent);
                    finish();
                }

And on the caller activity:

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {     
  super.onActivityResult(requestCode, resultCode, data); 
  switch(requestCode) { 
    case 1: { 
      if (resultCode == Activity.RESULT_OK) { 
          PATH = data.getStringExtra("FilePath"); 

          if(CheckIfFilesAlreadyExist(PATH)) //check if the files are already there.
          {
              if(!PATH.contains("Quran"))
                      PATH+="/Quran/";
              Main.Main_PATH=PATH;
              Toast.makeText(mContext, "The files have been found", Toast.LENGTH_LONG).show();

              Intent returnIntent = new Intent();
              setResult(RESULT_OK,returnIntent);        
              finish();

          }

          else{
          PATH+="/Quran/";
          Main.Main_PATH=PATH;
          edittext_开发者_开发百科Dialog.setText(PATH);
          goodFileChoosen=true;
          }
      }

      break; 
    } 
  } 
}

Why is the FC happening?

EDIT1: dirSize() :

private long dirSize(File dir) {

    long result = 0;
    File[] fileList = dir.listFiles(); //line 387

    for(int i = 0; i < fileList.length; i++) {
        // Recursive call if it's a directory
        if(fileList[i].isDirectory()) {
            result += dirSize(fileList [i]);
        } else {
            // Sum the file size in bytes
            result += fileList[i].length();
        }
    }
    return result; // return the file size
}


The FC is happening at line 387 of DataDownload.java in your dirSize() method. Without seeing your full code, I don't know why, but look at the objects referenced on that line and look for an object that has not been created / initialised.

One possibility is that data.getStringExtra("FilePath"); is returning null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜