title: Toggle Navigation Drawer 'open' on Button/ Image click
body: <p>I've created a fragment that is hooked to an XML containing one image view. A navigation drawer (using actionbar compat) is set up inside activity_main.java and is working fine. What i'm wanting to do is, when I tap on the image inside the fragment, the navigation drawer should 'toggle open'.</p>
  
  <p>The following code inside onCreateView method returns a null pointer:</p>
  
  <pre><code>    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedinstanceState)
              {   
  
                  View view=inflater.inflate(R.layout.home, container, false);
  
                  ImageView img=(ImageView)view.findViewById(R.id.imageView1);
  
                 // Defined inside activity_main.xml
                  final LinearLayout mDrawer = (LinearLayout) view.findViewById(R.id.drawer); 
  
                 // Defined inside activity_main.xml
                  final DrawerLayout mDrawerLayout = (DrawerLayout)view.findViewById(R.id.drawer_layout); 
  
                  img.setOnClickListener(new OnClickListener() {
  
                      @Override
                      public void onClick(View v) {
  
                       mDrawerLayout.openDrawer(mDrawer);
  
                      }
                  });
  
                  return view;    
                  }
  </code></pre>
  
  <p>A null pointer is returned at the following statement:</p>
  
  <blockquote>
    <p>mDrawerLayout.openDrawer(mDrawer);</p>
  </blockquote>