I am trying to hide a view/layout when one of the menu items is clicked but i keep getting a nullpointerexception.

This is how i am doing it.

```
RelativeLayout relativeLayout;
relativeLayout = (RelativeLayout) findViewById(R.id.layouttohide);

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_cog:
        if (relativeLayout.isShown() == true) {
            relativeLayout.setVisibility(relativeLayout.GONE);
        }else {
            relativeLayout.setVisibility(relativeLayout.VISIBLE);
        }

        return true;
    case R.id.action_stuff:
        Toast.makeText(getApplicationContext(),
                  item.getTitle(), Toast.LENGTH_SHORT).show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

```

In the XML file this is how i have the layout setup.

```
<RelativeLayout
    android:id="@+id/layouttohide"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="0dp"
    android:background="#025fb6"
    android:visibility="visible" >

```

Here is the error

```
08-10 18:56:23.936: E/AndroidRuntime(6473): FATAL EXCEPTION: main
08-10 18:56:23.936: E/AndroidRuntime(6473): java.lang.NullPointerException
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.app.MainActivity.onOptionsItemSelected(MainActivity.java:156)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.app.Activity.onMenuItemSelected(Activity.java:2534)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:372)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(ActionBarActivity.java:244)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(ActionBarActivityDelegateICS.java:164)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:130)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(ActionBarActivityDelegateICS.java:308)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:965)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:514)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:99)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.view.View.performClick(View.java:4084)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.view.View$PerformClick.run(View.java:16966)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.os.Handler.handleCallback(Handler.java:615)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.os.Looper.loop(Looper.java:146)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at android.app.ActivityThread.main(ActivityThread.java:4777)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at java.lang.reflect.Method.invoke(Method.java:511)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-10 18:56:23.936: E/AndroidRuntime(6473):     at dalvik.system.NativeStart.main(Native Method)

```