简体   繁体   English

Android 应用程序,上传个人资料图片不起作用

[英]Android application, uploading profile picture not functioning

I am developing an android application which requires me the user to sign up and then set profile picture and user name.我正在开发一个 android 应用程序,它要求我用户注册然后设置个人资料图片和用户名。 the registration is working properly and sending the data to Firebase but when it comes to uploading the profile photo, the application reading the gallery and picks the image but does not send the image to the Firebase neither does it set it in the image view.注册工作正常并将数据发送到 Firebase 但是在上传个人资料照片时,应用程序会读取图库并选择图像,但不会将图像发送到 Firebase 也不会在图像视图中设置它。 below is the error i get upon examination since the application terminates at that point.以下是我在检查时遇到的错误,因为应用程序在那时终止。

E**/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.chatme, PID: 23039
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=123, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/0/1/content://media/external/images/media/211575/ORIGINAL/NONE/image/jpeg/79264842 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F211575/ORIGINAL/NONE/image%2Fjpeg/79264842} }} to activity {com.example.chatme/com.example.chatme.profile}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageURI(android.net.Uri)' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4309)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4353)
        at android.app.ActivityThread.-wrap20(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6548)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageURI(android.net.Uri)' on a null object reference
        at com.example.chatme.profile.onActivityResult(profile.java:108)
        at android.app.Activity.dispatchActivityResult(Activity.java:7311)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4305)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4353) 
        at android.app.ActivityThread.-wrap20(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6548) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)** 

The error is occurring because the image view in which you setting the image, is null.发生错误是因为您设置图像的图像视图是 null。 Did you initialise it?你初始化了吗? If it is not initialised, it will crash because java will take it as null.setImageUri() but you cannot do anything on null.如果未初始化,它将崩溃,因为 java 会将其视为null.setImageUri()但您无法对 null 执行任何操作。 So initialise the image view in order to get safe from the error因此初始化图像视图以免受错误影响

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM