public void loadUserInformation() {
final String mNumber = getActivity().getIntent().getStringExtra("Phone_Number");
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usesrRef = rootRef.child("Users").child(uid);
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
EditText Name = (EditText) rootView.findViewById(R.id.Name);
ImageView profilePic = (ImageView)rootView.findViewById(R.id.profilePic);
for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){
String name=postSnapshot.child("Name").getValue().toString();
String email=postSnapshot.child("Email").getValue().toString();
String status=postSnapshot.child("Status").getValue().toString();
String quote=postSnapshot.child("Quote").getValue().toString();
String number = postSnapshot.child("Phone_Number").getValue().toString();
String image = dataSnapshot.child("Image").getValue().toString();
Name.setText(name);
Email.setText(email);
Status.setText(status);
Quote.setText(quote);
Number.setText(number);
Picasso.get().load(image).into(profilePic);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getActivity(),"Error Loading UserDetails",Toast.LENGTH_LONG).show();
}
};
usesrRef.addListenerForSingleValueEvent(eventListener);
}
I have this method and the database will have name,email's values but wont have values from status quote... so if i use this method it will obviously give a nullpointerexception because the data is null... how to avoid that? Like i know the data is null so how to fetch the rest of the data but i want to show the null data has NULL or something... how do i achieve this