title: How to reference a TextView in a separate layout file?
body: <p>I have built a navigation activity composed of 3 xml files, namely</p>
  
  <ul>
  <li><p>home_activity.xml</p></li>
  <li><p>nav_header.xml</p></li>
  <li><p>drawer_menu.xml</p></li>
  </ul>
  
  <p>home_activity.xml brings these together and is set as the content view in HomeActivity.java. </p>
  
  <p>Now, I'm programmatically trying to set the text of a TextView, in the nav_header.xml file but ending up with a Null Pointer Exception. I can see why, but don't quite know how to overcome this. How does one reference the original TextView and not a copy of it as is the outcome of inflating and adding it.</p>
  
  <p>PS. I have 2 weeks of Android experience,</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);
  
  
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, 
    toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
  
  
    View nav_header = getLayoutInflater()
                      .inflate(findViewById(R.id.nav_header), null);
  
    TextView text_username = nav_header.findViewById(R.id.text_username);
    text_username.setText("There you go");
  
  }
  </code></pre>