i am finding difficulty in implementing navigation drawer in all activities. i have created a base activity called MainActivity which has all the features of navigation drawer.in all my activity i extend mainactivity. now when i run the app i get unfortunately stopped in logcat the error points to "Attempt to invoke virtual method 'void android.support.v4.app.ActionBarDrawerToggle.syncState()' on a null object reference
at com.example.rahulrk.navigationdrawer.MainActivity.onPostCreate(MainActivity.java:194)"
on that particular line i have "mDrawerToggle.syncState();"
this is the code for baseactivity
declaration part
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
protected RelativeLayout _completeLayout, _activityLayout;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
public void set(String[] navMenuTitles,TypedArray navMenuIcons) {
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
navDrawerItems = new ArrayList<NavDrawerItem>();
if(navMenuIcons==null)
{
for(int i=0;i<navMenuTitles.length;i++)
{
navDrawerItems.add(new NavDrawerItem(navMenuTitles[i]));
}
}else
{
for(int i=0;i<navMenuTitles.length;i++)
{
navDrawerItems.add(new NavDrawerItem(navMenuTitles[i],navMenuIcons.getResourceId(i, -1)));
}
}
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.android,
R.string.app_name,
R.string.app_name
) {
public void onDrawerClosed(View view)
{
getSupportActionBar().setTitle(mTitle);
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView)
{
getSupportActionBar().setTitle(mDrawerTitle);
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
private class SlideMenuClickListener implements
ListView.OnItemClickListener
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
displayView(position);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
return super.onPrepareOptionsMenu(menu);
}
private void displayView(int position)
{
switch (position)
{
case 0:
Intent intent = new Intent(this, First.class);
startActivity(intent);
finish();
break;
case 1:
Intent intent1 = new Intent(this, Second.class);
startActivity(intent1);
finish();
break;
default:
break;
}
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
where could i have made a mistake. please i need guidence