保存后未显示个人资料图片(仅显示空白屏幕)
我正在尝试上传用户个人资料图像并存储在firebase中.我的图像成功存储在firebase存储中和用户数据库中.
I am trying to upload user profile image and store in firebase.My image successfully stores in firebase storage and in the user database.
当我上传图像时,它会显示在屏幕上,但是一旦我保存并重新打开设置以查看个人资料图像,它就不会显示,只会显示空白的白色屏幕(但是重新打开时会显示名称和电话,仅图片未显示)
When I upload the image it shows on my screen,but once I save and reopen the settings to see the profile image,it does not show,it just shows blank white screen(but the name and phone show when reopened,only image does not show)
我已经附上了从db获取值并在ui中显示的代码,还添加了saveUserInformation(),当用户单击保存图像"按钮时该调用被调用,此函数将名称,电话和profileimage保存在db中.我在下面添加了数据库的屏幕快照,还添加了我遇到的错误摘要.
I have attached the code that gets value from db and shows in ui and also added the saveUserInformation() which is called when the user clicks the save image button and this function saves name,phone and profileimage in db. I have added screenshot of database below and also added the snippet of error I am getting.
我在做什么错了?
这是我在控制台上记录的滑行输出: 个人资料img:目标:android.support.v7.widget.AppCompatImageView {528bbb2 V.ED..C .. ...... ID 0,0-300,300#7f0a00b9 app:id/profileImage} [CDS] rx超时:0
This is what glide outputs when i console logged it : profile img here:Target for: android.support.v7.widget.AppCompatImageView{528bbb2 V.ED..C.. ......ID 0,0-300,300 #7f0a00b9 app:id/profileImage}[CDS]rx timeout:0
mCustomerDatabase.addValueEventListener(object :ValueEventListener{
override fun onDataChange(dataSnapshot: DataSnapshot) {
if(dataSnapshot.exists() && dataSnapshot.childrenCount>0){
val map:Map<*,*> = dataSnapshot.value as Map<*,*>
if(map["name"] !=null){
mName=map["name"].toString()
mNameField.setText(mName)
}
if(map["phone"]!=null){
mPhone=map["phone"].toString()
mPhoneField.setText(mPhone)
}
if(map["profileImageUrl"]!=null){
mProfileImageUrl=map["profileImageUrl"].toString()
Glide.with(applicationContext).load(mProfileImageUrl).into(mProfileImage)
val a=Glide.with(applicationContext).load(mProfileImageUrl).into(mProfileImage)
print("profile img here:$a")
}
}
}
override fun onCancelled(p0: DatabaseError) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
private fun saveUserInformation(){
mName=mNameField.text.toString()
mPhone=mPhoneField.text.toString()
val userInfo=HashMap<String,Any>()
userInfo.put("name",mName)
userInfo.put("phone",mPhone)
mCustomerDatabase.updateChildren(userInfo)
if(resultUri!=null){
val imagePath:StorageReference=mStorage.child("customer_profile_image").child(userId).child(resultUri.lastPathSegment )
val uploadTask:UploadTask=imagePath.putFile(resultUri)
uploadTask.addOnSuccessListener(OnSuccessListener <UploadTask.TaskSnapshot>(){taskSnapshot->
val downloadUrl: Task<Uri> =taskSnapshot.storage.downloadUrl
val newImage= HashMap<String,Any>()
newImage["profileImageUrl"] = downloadUrl.toString()
mCustomerDatabase.updateChildren(newImage)
}).addOnFailureListener(OnFailureListener() {
Toast.makeText(this,"Profile image not uploaded",Toast.LENGTH_SHORT).show()
})
}
finish()
}
Load failed for com.google.android.gms.tasks.zzu@c0645c1 with size [300x300]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 3 causes:
java.io.FileNotFoundException(/com.google.android.gms.tasks.zzu@c0645c1: open failed: ENOENT (No such file or directory))
java.io.FileNotFoundException(No such file or directory)
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
There was 1 cause:
java.io.FileNotFoundException(/com.google.android.gms.tasks.zzu@c0645c1: open failed: ENOENT (No such file or directory))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.io.FileNotFoundException(/com.google.android.gms.tasks.zzu@c0645c1: open failed: ENOENT (No such file or directory))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: /com.google.android.gms.tasks.zzu@c0645c1: open failed: ENOENT (No such file or directory)
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: No such file or directory
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.content.res.AssetFileDescriptor, LOCAL
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: No such file or directory
02-04 15:21:14.109 25281-25281/com.sarah.taxi I/Glide: Root cause (1 of 3)
java.io.FileNotFoundException: /com.google.android.gms.tasks.zzu@c0645c1: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:487)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at android.content.ContentResolver.openInputStream(ContentResolver.java:689)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResourceFromUri(StreamLocalUriFetcher.java:85)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:60)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:15)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:473)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at android.content.ContentResolver.openInputStream(ContentResolver.java:689)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResourceFromUri(StreamLocalUriFetcher.java:85)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:60)
at com.bumptech.glide.load.data.StreamLocalUriFetcher.loadResource(StreamLocalUriFetcher.java:15)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
02-04 15:21:14.110 25281-25281/com.sarah.taxi I/Glide: Root cause (2 of 3)
java.io.FileNotFoundException: No such file or directory
at android.os.Parcel.openFileDescriptor(Native Method)
at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:270)
at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:200)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:966)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:894)
at com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher.loadResource(FileDescriptorLocalUriFetcher.java:22)
at com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher.loadResource(FileDescriptorLocalUriFetcher.java:14)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:397)
at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:119)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:153)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:144)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:49)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
Root cause (3 of 3)
java.io.FileNotFoundException: No such file or directory
at android.os.Parcel.openFileDescriptor(Native Method)
at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:270)
at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:200)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:966)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:894)
at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:22)
at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:13)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:397)
at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:119)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:153)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:144)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:49)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:397)
at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:119)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:153)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:144)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:49)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:99)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
您遇到以下错误:
com.google.android.gms.tasks.zzu@c0645c1的加载失败
Load failed for com.google.android.gms.tasks.zzu@c0645c1
因为您正在尝试显示不存在的图像.正如我在您的数据库中看到的那样,profileImageUrl
属性包含一个无效有效的图像网址.
Because you are trying to display an image that does not exist. As I see in your database, the profileImageUrl
property holds an image url that is not valid.
看到红线了吗?它实际持有的是内存中对象的地址,而不是图像的URL.之所以发生这种情况,是因为您要在downloadUrl
对象上调用toString()
方法.因此,获取下载URL的方法不正确. 此 是获取网址的正确方法.一旦获得图像的url并将其添加到数据库中,一切将按预期工作.
See the red line? What it actually holds is the address of an object from the memory and not an image url. This is happening because you are calling toString()
method on the downloadUrl
object. So the way you are get the donwload url is not correct. This is the correct way for getting the url. Once you get url of the image and you add it to the database and everything will work as expected.