0
The Code I’m using is this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cotacao);
mTextView = (TextView) findViewById(R.id.textFarm);
FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
mDataBaseRef = ConfiguracaoFirebase.getFirebase().child("usuario").child("nome");
mDataBaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String s = dataSnapshot.getValue(String.class);
Toast.makeText(CotacaoActivity.this, "O que aparece! " + s, Toast.LENGTH_SHORT).show();
setTextView(s);
}
@Override
public void onCancelled(DatabaseError databaseError) {
setTextView(databaseError.toString());
}
});
I need to insert this name into a Textview. It only returns null. I’ve tried several examples and answers from you. Someone can help.
.child("usuario").child("nome")
does not exist. It has to be.child("usuario").child("{ID_DO_USUARIO}").child("nome")
. At least according to the structure you posted there in the image– Artur Trapp
Ok. Then I put the user id and it will display the name? mDataBaseRef = Configuracaofirebase.getFirebase(). Child("user"). Child(userid). Child("name");
– Everlanio Paulo
Probably
– Artur Trapp
I checked that the mDataBaseRef user is null, even after logging in to Activity login (first Activity). After logging in the main screen opens with the menus, and it chooses which one should go, when entering new Activity (third ativity) the user is presented as null.
– Everlanio Paulo
I did the check like this: "Toast.makeText(Cotacaoactivity.this, "What appears! " + mDataBaseRef, Toast.LENGTH_SHORT). show();" The return of "mDataBaseRef=null". Can anyone indicate why the user name is null? Called here: mDataBaseRef = Configuracaofirebase.getFirebase(). Child("user"). Child(userid). Child("name");and thereby not displaying the user’s name?
– Everlanio Paulo
I got it sorted out! It was careless of me.
– Everlanio Paulo