I'm trying to use Glide to load an image from local storage with no success.
我尝试使用滑动来加载本地存储中的图像,但没有成功。
Glide.with(mContext)
.load(pictureUri) // Uri of the picture
.transform(new CircleTransform(..))
.into(profileAvatar);
This is the error I get:
这是我得到的错误:
java.lang.Exception: Failed to load model: '/storage/emulated/0/DCIM/Camera/IMG_20150831_180900.jpg'
at com.bumptech.glide.request.GenericRequest.onSizeReady(GenericRequest.java:441)
at com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.getSize(ViewTarget.java:211)
at com.bumptech.glide.request.target.ViewTarget.getSize(ViewTarget.java:100)
at com.bumptech.glide.request.GenericRequest.begin(GenericRequest.java:272)
at com.bumptech.glide.manager.RequestTracker.resumeRequests(RequestTracker.java:83)
at com.bumptech.glide.RequestManager.resumeRequests(RequestManager.java:180)
at com.bumptech.glide.RequestManager.onStart(RequestManager.java:203)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onStart(ActivityFragmentLifecycle.java:50)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onStart(SupportRequestManagerFragment.java:135)
at android.support.v4.app.Fragment.performStart(Fragment.java:1986)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1051)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1197)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1179)
at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1996)
at android.support.v4.app.FragmentController.dispatchStart(FragmentController.java:176)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:517)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.Activity.performRestart(Activity.java:6063)
at android.app.Activity.performResume(Activity.java:6068)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
3 个解决方案
#1
68
While waiting for someone to respond, I tried to make a File
instance from the Uri
and load that. It works! Weird!
在等待别人响应时,我尝试从Uri中创建一个文件实例并加载它。它的工作原理!奇怪!
Glide.with(mContext)
.load(new File(pictureUri.getPath())) // Uri of the picture
.transform(new CircleTransform(..))
.into(profileAvatar);
#2
#3
0
Make sure that the Uri is from file.
确保Uri来自文件。
Uri photoUri = Uri.fromFile( new File( preferences.getPhotoUrl()));
Glide.with(this).load( photoUri).into( civUserProfilePhoto);
#1
68
While waiting for someone to respond, I tried to make a File
instance from the Uri
and load that. It works! Weird!
在等待别人响应时,我尝试从Uri中创建一个文件实例并加载它。它的工作原理!奇怪!
Glide.with(mContext)
.load(new File(pictureUri.getPath())) // Uri of the picture
.transform(new CircleTransform(..))
.into(profileAvatar);
#2
8
If you pass an Uri
instance it better be compliant, it looks like yours doesn't have a schema (file://
).
如果您传递一个Uri实例,它最好是兼容的,它看起来像您的没有模式(文件://)。
You can check how Uri
, String
and File
models are loaded to debunk the weirdness :)
您可以检查如何加载Uri、字符串和文件模型,以揭穿这种怪异:)
#3
0
Make sure that the Uri is from file.
确保Uri来自文件。
Uri photoUri = Uri.fromFile( new File( preferences.getPhotoUrl()));
Glide.with(this).load( photoUri).into( civUserProfilePhoto);