0

I want to show user Profile image for each post. I wrote a code for this but i am getting an error.

enter image description here

//Here is error---

FATAL EXCEPTION: main
Process: com.example.serhat.blog, PID: 5614                                                                           java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() 
at com.google.firebase.database.DatabaseReference.child(Unknown Source)
at com.example.serhat.blog.MainActivity$2.populateViewHolder(MainActivity.java:95)
at com.example.serhat.blog.MainActivity$2.populateViewHolder(MainActivity.java:80)

//Here is my code
 //Profile image//
                mDatabaseUsers.child(model.getUserid()).child("image").addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        String image = dataSnapshot.getValue(String.class);
                        viewHolder.setProfileImage(MainActivity.this,image);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

//Here is blog class 

    private String title,description,image,uid,username,senddate;


    public Blog()

    {

    }

    public Blog(String title, String description, String image, String uid, String username,String senddate,String profileimageUri) {
        this.title = title;
        this.description = description;
        this.image = image;
        this.uid = uid;
        this.username = username;
        this.senddate=senddate;
    }
    public String getUserid() {
        return uid;
    }
    public void setUserid(String uid) {
        this.uid = uid;
    }

Solved. Thanks for your answers. The problem is my database stracture in firebase i changed 'uid' to 'userid' and problem solved.

The problem is method names and the domain name in the database are not the same.

Zoe
  • 27,060
  • 21
  • 118
  • 148

1 Answers1

1

It seems model.getUserid() in mDatabaseUsers.child(model.getUserid()) is null which causes the NullPointerException.

Why it's null is hard to tell with the code you've provided, but you should be able to debug it.

Casper
  • 471
  • 7
  • 12