-1

I'm trying to using fragment layout and navigation drawer for menu option, but I'm getting error:

java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.support.v7.widget.Toolbar

My java file:

My java file

My fragment file:

My fragment file

Micho
  • 3,929
  • 13
  • 37
  • 40
disha
  • 51
  • 1
  • 8

3 Answers3

1

give id in your xml fragment like android:id="@+id/fragment_drawer"

 mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_drawer);

 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

        }

    };   
     // Set up the drawer.
    mNavigationDrawerFragment.setUp(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer));
0

Comment this line and run it:

mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);//this is wrong casting
Avinash Roy
  • 953
  • 1
  • 8
  • 25
0

I recomend you that please remove the following code from Your Java code and the try to Build the project

mtoolbar = (ToolBar) findviewById(R.id.mtoolbar);

You Dont need add action bar separately....!

pawan kasar
  • 170
  • 1
  • 6
  • Heyy..ppl thank u.....Can u help me to clear this error........while running an appilication am getting a java.lang.NullPointerException in the line getSupportActionBar().setDisplayShowHomeEnabled(true); – disha Jul 03 '17 at 07:26