0

I am developing an android application which requires me the user to sign up and then set profile picture and user name. 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. 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)** 
Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38

1 Answers1

1

The error is occurring because the image view in which you setting the image, is 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. So initialise the image view in order to get safe from the error

Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38