-1

I want to change the textview, email which are in nav_header by OnCreate, but i get the error On a null object reference.

Picture 1 Picture 2

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                  at multimedia.slidemenu.MainActivity.onCreate(MainActivity.java:26)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Json
  • 59
  • 3
  • 13
  • http://stackoverflow.com/questions/34973456/how-to-change-text-of-a-textview-in-navigation-drawer-header check this link please, and try it – Francisco Melicias May 16 '17 at 10:59
  • 3
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Phantômaxx May 16 '17 at 11:41

1 Answers1

0

thanks Melicias, it works for me using this code :

NavigationView navigationView= (NavigationView) findViewById (R.id.navigationView);    
View header = navigationView.getHeaderView(0);

And then I can set the text like this:

TextView text = (TextView) header.findViewById(R.id.text);
text.setText("xxxxx");
Json
  • 59
  • 3
  • 13