Toggle Navigation Drawer 'open' on Button/ Image click

These lines are referencing the wrong view:

final LinearLayout mDrawer = (LinearLayout) view.findViewById(R.id.drawer); 
final DrawerLayout mDrawerLayout = (DrawerLayout)view.findViewById(R.id.drawer_layout);

They are looking for the drawer in 'R.layout.home' because that's what you inflate and set to the view variable, findViewById() returning null because it's not there.

If this view is a child of activity_main then you should be able to change these to:

final LinearLayout mDrawer = (LinearLayout) getActivity().findViewById(R.id.drawer); 
final DrawerLayout mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);

Additionally, I'd make these class members and not final.


It works on Button click

mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            drawer.openDrawer(GravityCompat.START);

        }
    });

It works on Image click

mImageview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            drawer.openDrawer(GravityCompat.START);

        }
    });