Skip to content Skip to sidebar Skip to footer

Error In Navigation Drawer

Somehow I am getting a null pointer Exception in this method @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); acti

Solution 1:

I found the problem actually I was doing this

        actionBarToggle = new ActionBarDrawerToggle(this, drawerLayout,
            R.drawable.ic_drawer, R.string.drawerOpen, R.string.drawerClose) {
        publicvoidonDrawerClosed(View view) {
            getSupportActionBar().setTitle("Close");
            ActivityCompat.invalidateOptionsMenu(activity);
        }

        publicvoidonDrawerOpened(View main) {
            getSupportActionBar().setTitle("Open");
            ActivityCompat.invalidateOptionsMenu(activity);
        }
    };
    drawerLayout.setDrawerListener(actionBarToggle); 
    drawerLayout = (DrawerLayout) findViewById(R.id.navigationDrawer);//This should be    before actionBarToggle

So I was intailizing the drawerLayout after using it in actionBarToggle.

Solution 2:

Follow the instructions here.

http://developer.android.com/training/implementing-navigation/nav-drawer.html

Your actionBarToggle object is null. Create the ActionBarDrawerToggle and assign it to your variable before you try to use it.

Solution 3:

I also had NullPointerException. That was a silly mistake, I was doing:

drawerToggle = newActionBarDrawerToggle(this,
            drawerLayout,
            R.drawable.ic_drawer,
            1,
            2){ ... }

I hardcoded those two strings for accesibility by saying 1,2, because I found those strings unimportant. As far as I was running Android 2.3-4.3 everything was ok, but on 4.4 I was getting an exception. Solution is simple: just create those two strings in values/strings.xml

Sorry for my english :)

Post a Comment for "Error In Navigation Drawer"