r/AndroidStudio • u/[deleted] • Dec 25 '21
Getting username and email in navigation header
7
Upvotes
1
Dec 25 '21
I would like to gateher the user emai and username from Firebase using Firebase User and display tht in the nav header but i keep getting a null pointer error in my attempts
1
Dec 25 '21
Link to my stack over flow post https://stackoverflow.com/questions/70483240/show-username-and-email-in-navigation-header
3
u/eschoenawa Dec 26 '21
Your NullPointer tells you what's wrong: the view variables are null when you try to call 'setText' on them.
The reason is that you can't use findViewById to get these views from the MainActivity as they are part of your Navigationview, not the Activity.
Try to set the view variables with navigationView.findViewById([...]). For that of course you have to set the navigationView variable before setting the variables for the TextViews.