我想为每个帖子显示用户个人资料图片。我为此编写了一个代码但是我收到了一个错误。
//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;
}
解决。谢谢你的回答。问题是我在firebase中的数据库结构我改变了#uid'到用户ID'问题解决了。
问题是方法名称和数据库中的域名不一样。
答案 0 :(得分:1)
model.getUserid()
中的mDatabaseUsers.child(model.getUserid())
似乎是null
,导致NullPointerException。
为什么它的null很难用您提供的代码来判断,但您应该可以调试它。