title: Android Api 23 Change Navigation View headerLayout textview
body: <p>I am testing the Navigation Drawer sample project in android and i have a problem setting the text in navigation view profile header.</p>
  
  <p>This is my code:</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
              this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
      drawer.setDrawerListener(toggle);
      toggle.syncState();
  
      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
      navigationView.setNavigationItemSelectedListener(this);
  
      TextView text = (TextView) findViewById(R.id.textView);
      texto.setText("HELLO");
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
  android:layout_width="match_parent" android:layout_height="match_parent"
  android:fitsSystemWindows="true" tools:openDrawer="start"&gt;
  
  &lt;include layout="@layout/app_bar_main" android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  &lt;android.support.design.widget.NavigationView android:id="@+id/nav_view"
      android:layout_width="wrap_content" android:layout_height="match_parent"
      android:layout_gravity="start" android:fitsSystemWindows="true"
      app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>nav_header_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height"
  android:background="@drawable/side_nav_bar"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
  android:gravity="bottom"&gt;
  
  &lt;ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:paddingTop="@dimen/nav_header_vertical_spacing"
      android:src="@android:drawable/sym_def_app_icon" android:id="@+id/imageView" /&gt;
  
  &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content"
      android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Android Studio"
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" /&gt;
  
  &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:text="android.studio@android.com" android:id="@+id/textView" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When i try to set the text of the textview i always get this error and it only happens with api level 23:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method   'void android.widget.TextView.setText(java.lang.CharSequence)' on a null   object reference
  </code></pre>
  
  <p>How can i change the Textview text of the nav_header_main.xml from the main activity??</p>
  
  <p>Thanks in advance</p>