gpt4 book ai didi

android - onActivityResult崩溃 “Failure delivering result”

转载 作者:行者123 更新时间:2023-12-03 17:42:08 25 4
gpt4 key购买 nike

我有一个从AndDev网站获得的FileBrowser Activity 。问题是它停止工作并且崩溃了,这是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();
}

并在 call 者 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;
}
}
}

为什么会发生FC?

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
}

最佳答案

FC正在DataDownload.java方法中的dirSize()的第387行发生。没有看到完整的代码,我不知道为什么,但是请查看该行上引用的对象并查找尚未创建/初始化的对象。

一种可能性是data.getStringExtra("FilePath");返回null

关于android - onActivityResult崩溃 “Failure delivering result”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6579781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com