title: Open Navigation Drawer with layout on click event
body: <p>I have two navigation drawer, one with a ListView and the second with a Layout. The first Navigationdrawer works fine, but the second can't open it on a button click.</p>
  
  <p>Here is the MainActivity xml code:</p>
  
  <pre><code>&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="match_parent"
  android:fitsSystemWindows="true"
  android:layout_gravity="right"
  android:orientation="vertical"&gt;
  
  &lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/orange"
          android:id="@+id/toolbar"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
          app:navigationIcon="@drawable/arrow"
          app:title="MyGames"
          &gt;
              &lt;Button
                  android:id="@+id/rigthMenu"
                  android:background="@drawable/compose"
                  android:layout_width="36dp"
                  android:layout_height="36dp"
                  android:layout_marginRight="5dp"
                  android:layout_gravity="right" /&gt;
  
  
      &lt;/android.support.v7.widget.Toolbar&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;android.support.v4.widget.DrawerLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollIndicators="bottom"&gt;
  
  &lt;FrameLayout
      android:id="@+id/content_frame"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
  &lt;/FrameLayout&gt;
  
  &lt;ListView
      android:id="@+id/left_drawer"
      android:layout_width="300dp"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:choiceMode="singleChoice"
      android:divider="@android:color/transparent"
      android:dividerHeight="2dp"
      android:background="#ffffff"
      android:scrollbars="vertical"/&gt;
  
      &lt;include
          android:id="@+id/layRigth"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="end"
          layout="@layout/rigth_menu" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the rigthMenu layout xml code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#ffffff"
  android:gravity="left"&gt;
  
  &lt;CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="New CheckBox"
      android:id="@+id/checkBox2"
      android:layout_gravity="center_horizontal" /&gt;
  
  &lt;CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="New CheckBox"
      android:id="@+id/checkBox"
      android:layout_gravity="center_horizontal" /&gt;
  
  &lt;CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="New CheckBox"
      android:id="@+id/checkBox4"
      android:layout_gravity="center" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>and here is the MainActivity OnCreate code:</p>
  
  <pre><code>    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    //  mDrawerLayout2 = (DrawerLayout)findViewById(R.id.layRigth);
      android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
      toolbar.setNavigationOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              onIcon = !onIcon;
              if (onIcon == true) {
                  mDrawerLayout.openDrawer(mDrawerList);
              } else {
                  mDrawerLayout.closeDrawer(mDrawerList);
              }
          }
      });
  
      Button rigthMenu = (Button)findViewById(R.id.rigthMenu);
      rigthMenu.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              final LayoutInflater factory = getLayoutInflater();
              final View text = factory.inflate(R.layout.rigth_menu, null);
              mDrawerLayout2 = (DrawerLayout)text.findViewById(R.id.layRigth);
              mDrawerLayout2.openDrawer(mDrawerLayout2);
          }
      });
  
      Drawable x = toolbar.getNavigationIcon();
      getDefaultSettings("Image", this);
    //  mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
  
      mFragmentManager = getSupportFragmentManager();
      mFragmentTransaction = mFragmentManager.beginTransaction();
      mFragmentTransaction.replace(R.id.content_frame,new TabFragment()).commit();
  
      // Initializing
      dataList = new ArrayList&lt;DrawerItem&gt;();
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
      mDrawerList = (ListView) findViewById(R.id.left_drawer);
  
      // Add Drawer Item to dataList
      dataList.add(new DrawerItem(R.mipmap.ps4miniatura, GREEN, 1));
      dataList.add(new DrawerItem(R.mipmap.ps4miniatura, "PC", 0));
      dataList.add(new DrawerItem(0, " ", 2));
      adapter = new CustomDrawerAdapter(this, R.layout.custom_drawer_item, adapter,
              dataList);
  
   //   addItem.giveAdapter(adapter);
      mDrawerList.setAdapter(adapter);
      mDrawerList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
  
      if (savedInstanceState == null) {
          SelectItem(1);
      }
  }
  </code></pre>
  
  <p>Logcat error:</p>
  
  <pre><code>12-08 08:40:52.936 15587-15587/com.tutecentral.navigationdrawer E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.tutecentral.navigationdrawer, PID: 15587
                                                                                java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.openDrawer(android.view.View)' on a null object reference
                                                                                    at com.tutecentral.navigationdrawer.MainActivity$2.onClick(MainActivity.java:75)
                                                                                    at android.view.View.performClick(View.java:4820)
                                                                                    at android.view.View$PerformClick.run(View.java:20157)
                                                                                    at android.os.Handler.handleCallback(Handler.java:815)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5578)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
  </code></pre>
  
  <p>I have a nullPointException. How can I get the view of the layout rigthMenu?</p>