我正在尝试做一个基本的社交应用程序,但是主要活动中的搜索Fragment导致应用程序崩溃,并显示错误代码:“ java.lang.NullPointerException:尝试调用虚拟方法'boolean java.lang。空对象引用上的String.equals(java.lang.Object)'
该消息说,我正在尝试对不应该存在的空对象执行if()语句。错误在以下代码的if后面:
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int position) {
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final UserObject user = mUsers.get(position);
viewHolder.username.setText(user.getUsername());
Glide.with(context).load(user.getImageurl()).into(viewHolder.image_profile);
isFollowing(user.getId(), viewHolder.follow);
if(user.getId().equals(firebaseUser.getUid())){
viewHolder.follow.setVisibility(View.GONE);
}
This is suppose to hide a follow button when the user object has the
user id.
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
User user = snapshot.getValue(User.class);
mUsers.add(user);
}