title: Change Picture and Text in Navigation Drawer Activity
body: <p>I want to change the drop down image and text programmatically when you create a new Navigation Drawer Activity. I tried this: (Assume currentUser.firstName is not null. </p>
  
  <pre><code>NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
      navigationView.setNavigationItemSelectedListener(this);
  
  
      TextView message  = (TextView) navigationView.findViewById(R.id.welcomeTextview);
      message.setText("Hello " + currentUser.firstName.toString());
  
      ImageView profilePicbtn = (ImageView)navigationView.findViewById(R.id.imageViewProfile);
      profilePicbtn.setBackgroundResource(R.drawable.nat_profile);
  </code></pre>
  
  <p>I did 'navigationView.findviewById()' because the imageView and TextView are in nav_header_dashboard.xml. When I run this, it crashes, if I remove the TextView and ImageView declaration it runs. I just want to change the picture at the top and provide a hello message when I click on the drop down menu. Also assume the image 'nat_profile' exits.</p>
  
  <p>These are my files:</p>
  
  <p>Dashboard.java</p>
  
  <pre><code>import android.graphics.Color;
  import android.graphics.PorterDuff;
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.PagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.design.widget.NavigationView;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import java.util.*;
  import android.content.Intent;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class Dashboard extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener {
  
  
   @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_dashboard);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  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);
  
      //testing lazaro
      //TextView message  = (TextView) navigationView.findViewById(R.id.welcomeTextview);
      //message.setText("Hello " + currentUser.firstName.toString());
  
      ImageView profilePicbtn = (ImageView)navigationView.findViewById(R.id.imageViewProfile);
      profilePicbtn.setBackgroundResource(R.drawable.nat_profile);
  </code></pre>
  
  <p>activity_dashboard.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_dashboard"
      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_dashboard"
      app:menu="@menu/activity_dashboard_drawer" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>nav_header_dashboard.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="@dimen/nav_header_height"
  android:background="@drawable/side_nav_bar"
  android:gravity="bottom"
  android:orientation="vertical"
  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"&gt;
  
  &lt;ImageView
      android:id="@+id/imageViewProfile"
      android:layout_width="90dp"
      android:layout_height="90dp"
      android:paddingTop="@dimen/nav_header_vertical_spacing"
      app:srcCompat="@drawable/nat_profile" /&gt;
  
  &lt;TextView
      android:id="@+id/welcomeTextview"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingTop="@dimen/nav_header_vertical_spacing"
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This is my strings.xml in values folder:</p>
  
  <pre><code>&lt;resources&gt;
     &lt;string name="app_name"&gt;Life Management&lt;/string&gt;
     &lt;string name="title_activity_login"&gt;Sign in&lt;/string&gt;
  
     &lt;!-- Strings related to login --&gt;
     &lt;string name="prompt_email"&gt;Email&lt;/string&gt;
     &lt;string name="prompt_password"&gt;Password (optional)&lt;/string&gt;
     &lt;string name="action_sign_in"&gt;Sign in or register&lt;/string&gt;
     &lt;string name="action_sign_in_short"&gt;Sign in&lt;/string&gt;
     &lt;string name="error_invalid_email"&gt;This email address is invalid&lt;/string&gt;
     &lt;string name="error_invalid_password"&gt;This password is too short&lt;/string&gt;
     &lt;string name="error_incorrect_password"&gt;This password is incorrect&lt;/string&gt;
     &lt;string name="error_field_required"&gt;This field is required&lt;/string&gt;
     &lt;string name="permission_rationale"&gt;"Contacts permissions are needed for providing email
      completions."
     &lt;/string&gt;
     &lt;string name="title_activity_dashboard"&gt;DashboardActivity&lt;/string&gt;
  
  &lt;string name="navigation_drawer_open"&gt;Open navigation drawer&lt;/string&gt;
  &lt;string name="navigation_drawer_close"&gt;Close navigation drawer&lt;/string&gt;
  
  &lt;string name="action_settings"&gt;Settings&lt;/string&gt;
  
  
  &lt;string name="action_signout"&gt;Sign Out&lt;/string&gt;
  &lt;string name="action_joy"&gt;JOY&lt;/string&gt;
  &lt;string name="action_passion"&gt;PASSION&lt;/string&gt;
  &lt;string name="action_givingback"&gt;GIVING BACK&lt;/string&gt;
  &lt;string name="section_format"&gt;Hello World from section: %1$d&lt;/string&gt;
  &lt;string name="title_activity_previous_cycle"&gt;Life Management&lt;/string&gt;
  &lt;string name="title_home"&gt;Home&lt;/string&gt;
  &lt;string name="title_dashboard"&gt;Dashboard&lt;/string&gt;
  &lt;string name="title_notifications"&gt;Notifications&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Crash Report:</p>
  
  <pre><code>11-05 10:37:32.621 2890-2890/com.example.seniorprojectfall.test E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.example.seniorprojectfall.test, PID: 2890
                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.seniorprojectfall.test/com.example.seniorprojectfall.test.Dashboard}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                    at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                    at android.os.Looper.loop(Looper.java:164)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                                    at **com.example.seniorprojectfall.test.Dashboard.onCreate(Dashboard.java:354)**
                                                                                    at android.app.Activity.performCreate(Activity.java:6975)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                                    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                                    at android.os.Looper.loop(Looper.java:164) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
  </code></pre>
  
  <p>Dashboard.java:354) is the line: message.setText("Hello " + currentUser.firstName.toString());</p>