I got a null pointer exeption error on Attempt to invoke virtual method void android.widget.TextView.setText(java.lang.CharSequence)'
on a null object reference.
public class MainActivity {
TextView servingqueue;
}
This is onCreate
DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mServingQueue = mRootRef.child("ServingQueue");
servingqueue = (TextView) findViewById(R.id.queueServing);
mServingQueue.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Double number = dataSnapshot.getValue(Double.class);
servingqueue.setText(String.valueOf(number));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
The error appeared right on
servingqueue.setText(String.valueOf(number));
It just does not want to pass the value from Firebase to my textview. I get force close from my app upon loading the activity.