setText in Navigation Drawer

I have activity with Navigation Drawer, I want to set text to NavigationDrawer HeaderView. I have written below code, but it gets crashed.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method ‘void android.widget.TextView.setText(int)’ on a null object

protected void onCreate(Bundle savedInstanceState) {


NavigationView navigationView = (NavigationView) findViewById(; navigationView.setNavigationItemSelectedListener(this);

TextView name = findViewById(;




Could you pls help to resolve this exception.

Thanks in advance

No Comments

Have More Question?

Subscribe For Daily Updates

Flutter Questions
Android Questions