gpt4 book ai didi

Android:IllegalArgumentException:无法找到包含/data/data/的已配置根目录

转载 作者:行者123 更新时间:2023-11-29 15:40:14 25 4
gpt4 key购买 nike

刚接触到适用于 Android 的 Glide 图像加载库。使用此处的代码:https://github.com/bumptech/glide/issues/459

完整项目在这里: https://github.com/mhurwicz/glide02

当我在 Android Studio 的模拟器中运行应用程序时出现以下异常:

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.glide02/cache/image_manager_disk_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0

其余的消息是:

at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.example.glide02.ShareTask.onPostExecute(ShareTask.java:37)
at com.example.glide02.ShareTask.onPostExecute(ShareTask.java:15)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

错误发生在FileProvider.getUriForFile()

@Override protected void onPostExecute(File result) {
if (result == null) { return; }
Uri uri = FileProvider.getUriForFile(context, context.getPackageName(), result);
share(uri); // startActivity probably needs UI thread
}

我已经查看了与此错误相关的其他几个问题,但看不出它们与我的案例有什么关系,这可能是因为我对这整个领域不熟悉。

任何帮助将不胜感激。

这是出现上述方法的类的完整代码:

class ShareTask extends AsyncTask<String, Void, File> {
private final Context context;

public ShareTask(Context context) {
this.context = context;
}
@Override protected File doInBackground(String... params) {
String url = params[0]; // should be easy to extend to share multiple images at once
try {
return Glide
.with(context)
.load(url)
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get() // needs to be called on background thread
;
} catch (Exception ex) {
Log.w("SHARE", "Sharing " + url + " failed", ex);
return null;
}
}
@Override protected void onPostExecute(File result) {
if (result == null) { return; }
Uri uri = FileProvider.getUriForFile(context, context.getPackageName(), result);
share(uri); // startActivity probably needs UI thread
}

private void share(Uri result) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_SUBJECT, "Shared image");
intent.putExtra(Intent.EXTRA_TEXT, "Look what I found!");
intent.putExtra(Intent.EXTRA_STREAM, result);
context.startActivity(Intent.createChooser(intent, "Share image"));
}

最佳答案

在我的例子中,这是 filepath.xml 中的解决方案

    <paths>
<root-path name="root" path="." />
</paths>

关于Android:IllegalArgumentException:无法找到包含/data/data/的已配置根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41754799/

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