Setting Visibility on a Drawer Menu
<p>I want my menu to display a sub-menu below it when the menu is clicked. I've tried several ways of doing that but I just can't make it work. The app crashes whenever I click the menu.</p>

<p>Here's my Java</p>

<pre><code>@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_gallery) {
        MenuItem acc1 = (MenuItem) findViewById(R.id.manage_profile);
    }
    else if (id == R.id.manage_profile) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.nav_gallery2) {
    }
    else if (id == R.id.search_school) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.school_vielnearby) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.school_vielall) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.nav_gallery3) {
    }
    else if (id == R.id.search_organization) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.organization_vielnearby) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    else if (id == R.id.organization_vielall) {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }
    return true;
}
</code></pre>

<p>And here's my menu XML</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
&lt;group
    android:id="@+id/menuall"&gt;
    &lt;item
        android:id="@+id/nav_gallery"
        android:icon="@android:drawable/ic_menu_gallery"
        android:title="My Account"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/manage_profile"
        android:checked="false"
        android:visible="false"
        android:title="      Manage Account"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/nav_gallery2"
        android:icon="@android:drawable/ic_menu_gallery"
        android:title="School"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/search_school"
        android:checked="false"
        android:visible="false"
        android:title="      Search School"/&gt;
    &lt;item
        android:id="@+id/school_vielnearby"
        android:checked="false"
        android:visible="false"
        android:title="      View Nearby"/&gt;
    &lt;item
        android:id="@+id/school_vielall"
        android:checked="false"
        android:visible="false"
        android:title="      View All"/&gt;
    &lt;item
        android:id="@+id/nav_gallery3"
        android:icon="@android:drawable/ic_menu_gallery"
        android:title="Organization"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/search_organization"
        android:checked="false"
        android:visible="false"
        android:title="      Search Organization"/&gt;
    &lt;item
        android:id="@+id/organization_vielnearby"
        android:checked="false"
        android:visible="false"
        android:title="      View Nearby"/&gt;
    &lt;item
        android:id="@+id/organization_vielall"
        android:checked="false"
        android:visible="false"
        android:title="      View All"/&gt;
&lt;/group&gt;
&lt;/menu&gt;
</code></pre>

<p>So basically I want my app to set the visibility to true when the menu is clicked.</p>

<p>Here's the logcat when I click a menu containing this code</p>

<pre><code>if (id == R.id.nav_gallery) {
        MenuItem acc1 = (MenuItem) findViewById(R.id.manage_profile);
        acc1.setVisible(true);

    }

    01-01 20:20:52.696  21622-21622/ph.schoolar.schoolar W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41bf7c08)
01-01 20:20:52.706  21622-21622/ph.schoolar.schoolar E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: ph.schoolar.schoolar, PID: 21622
    java.lang.NullPointerException
            at ph.schoolar.schoolar.StudentView.onNavigationItemSelected(StudentView.java:114)
            at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:150)
            at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
            at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
            at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
            at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:308)
            at android.view.View.performClick(View.java:4654)
            at android.view.View$PerformClick.run(View.java:19438)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
</code></pre>