У меня есть активность FileBrowser, которую я получил с сайта AndDev.Проблема в том, что он перестал работать и вылетает, вот 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
Вот что я делаю, когда пользователь выбрал нужную ему папку:
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();
}
И наактивность вызывающего абонента:
@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;
}
}
}
Почему происходит ФК?
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
}