1

I am using following code to get TextView from Navigationview's headerLayout.

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

txtName = (TextView) navigationView.findViewById(R.id.txtName);
txtName.setText("Guna");

This code works if I use following dependency

compile 'com.android.support:design:23.0.1'

But it throws NullPointerException at txtName.setText("Guna"); if I change the dependency to

compile 'com.android.support:design:23.1.0'

I don't know how to resolve this.

Exception Log from LogCat:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
halfer
  • 19,471
  • 17
  • 87
  • 173
Gunaseelan
  • 12,697
  • 10
  • 74
  • 118

0 Answers0