title: Drawerlayout opendrawer NullpointerException
body: <p>I'm using DrawerLayout for Navigation between different fragments. But in my application I'm not using toolbar, for toolbar I created a linear layout which is included in each fragment's layout and define Drawer layout publicly static in my main activity for accessing it from each fragment.And my drawerlayout is in main_activity.xml file.</p>
  
  <pre><code>&lt;RelativeLayout
  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"&gt;
  &lt;android.support.v4.widget.DrawerLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/drawerLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;FrameLayout
          android:id="@+id/mainContent"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;!-- The navigation drawer --&gt;
      &lt;RelativeLayout
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:id="@+id/drawerPane"
          android:layout_gravity="start"&gt;
  
          &lt;!-- Profile Box --&gt;
  
          &lt;RelativeLayout
              android:id="@+id/profileBox"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@drawable/background_material2"
              android:padding="8dp" &gt;
  
  
              &lt;ImageView
                  android:id="@+id/avatar"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/user2"
                  android:layout_marginTop="60dp" /&gt;
  
              &lt;LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="42dp"
  
                  android:layout_marginStart="15dp"
                  android:layout_marginLeft="15dp"
                  android:layout_marginTop="115dp"
                  android:layout_toRightOf="@+id/avatar"
                  android:layout_toEndOf="@+id/avatar"
  
                  android:orientation="vertical" &gt;
  
                  &lt;TextView
                      android:id="@+id/userName"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Sushant Kumar"
                      android:textAllCaps="true"
                      android:textColor="#ffffff"
                      android:textSize="16sp"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/desc"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="4dp"
  
                      android:text="8931839445"
                      android:textColor="#fff"
                      android:textSize="12sp" /&gt;
              &lt;/LinearLayout&gt;
          &lt;/RelativeLayout&gt;
  
          &lt;!-- List of Actions (pages) --&gt;
          &lt;ListView
              android:id="@+id/navList"
              android:layout_width="300dp"
              android:layout_height="match_parent"
              android:layout_below="@+id/profileBox"
              android:choiceMode="singleChoice"
              android:background="#ffffff" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:id="@+id/alert"
      android:visibility="gone"
      android:background="@color/PrimaryColor"
      &gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:gravity="center"
          android:layout_height="wrap_content"
          android:textStyle="bold"
          android:text="Getting Problems while connecting to Server."
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>In my main activity I initialize like this :</p>
  
  <pre><code>mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
  
      // Populate the Navigtion Drawer with options
      mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
      mDrawerList = (ListView) findViewById(R.id.navList);
      DrawerListAdapter adapter = new DrawerListAdapter(this, mNavItems);
      mDrawerList.setAdapter(adapter);
  </code></pre>
  
  <p>Here is my toolbar xml :</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:id="@+id/action_bar"
      android:orientation="horizontal"
      android:background="@color/PrimaryColor"
      android:layout_height="wrap_content"&gt;
      &lt;ImageView
          android:layout_width="50dp"
          android:padding="10dp"
          android:layout_height="50dp"
          android:id="@+id/togglebutton"
          android:src="@drawable/ic_menu"
          /&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="fill_parent"
          android:gravity="center"
          android:text="ABOUT MOOVO"
          android:id="@+id/title"
          android:textAllCaps="true"
          android:textSize="18sp"
          android:layout_marginRight="50dp"
          android:textStyle="bold"
          android:textColor="#FFFFFF"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here on click of Ic_menu icon I open the drawer pane from different fragments using this code :</p>
  
  <pre><code>Ic_menu.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              MainActivity.mDrawerLayout.openDrawer(MainActivity.mDrawerPane);
          }
      });
  </code></pre>
  
  <p>This working properly most of time but sometimes this give Nullpointerexception.</p>
  
  <pre><code>Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.openDrawer(android.view.View)' on a null object reference
  </code></pre>
  
  <p>How to solve this problem, any suggestions? </p>