title: Adding code for TextView item in Navigation Drawer header
body: <p>I currently have a Navigation Drawer implemented inside my app using <code>NavigationView</code>. The layout of the drawer is split into a header <code>drawer_header.xml</code> and a menu <code>drawer_menu.xml</code>. It looks something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/JYdVj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JYdVj.jpg" alt="Drawer"></a></p>
  
  <p>I am trying to set the user's name <code>DrawerNameTv</code> in the header in java code using <code>setText</code> instead of <code>xml</code> however I receive the following error:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference</p>
  </blockquote>
  
  <p>Here's the <code>Main_Activity.java</code></p>
  
  <pre><code>TextView DrawerName;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_activity);
  
      CustomToolbar = (Toolbar) findViewById(R.id.toolbar);
      DrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
      NavigationView = (NavigationView) findViewById(R.id.navigation_view);
      DrawerName = (TextView) findViewById(R.id.DrawerNameTv);
  
      DrawerName.setText("Test");
  
      ...
  </code></pre>
  
  <p>And the <code>drawer_header.xml</code></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:src="@drawable/user_pic" /&gt;
  
      &lt;TextView
          android:layout_height="wrap_content"
          android:layout_width="match_parent"
          android:textSize="20dp"
          android:layout_marginTop="120dp"
          android:id="@+id/DrawerNameTv" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Pardon me as I'm new to Android development.</p>