我有一个java.lang.NullPointerException,我不知道如何解决它。我的用户名没有出现在TextView中。
public class Main extends AppCompatActivity {
CircleImageView profilepic;
TextView profileuser;
FirebaseUser firebaseUser;
DatabaseReference reference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
profilepic = findViewById(R.id.profile_image);
profileuser = findViewById(R.id.username);
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
profileuser.setText(user.getUsername());
if (user.getImageURL().equals("default")){
profilepic.setImageResource(R.mipmap.ic_launcher);
}else{
Glide.with(Main.this).load(user.getImageURL()).into(profilepic);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
日志说我有错误profileuser.setText(user.getUsername());请帮助我。
慕姐4208626
慕慕森
相关分类