FindViewById (int) in Activity cannot be applied to (int, android.support.v7.widget.Toolbar

So, I followed the Slidnerd tutorial in the navigation box . The problem occurs when I try to create an instance of ActionBarDrawerToggle to indicate Activity , DrawerLayout and Toolbar .

 (NavigationDrawerFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_nav_drawer); drawerFragment.setUp((DrawerLayout) findViewById (R.id.drawer_layout, toolbar); 

I get the underlying error (R.id.drawer_layout toolbar, ). The error says: "findViewById (int) in Activity cannot be applied to (int, android.support.v7.widget.Toolbar" .

I tried the proposed solution, which was supposed to import the android.support.v4.app.Fragment file, but even after trying this, the problem still persists, I even tried the other way around. I also want to publish my relevant code if necessary.

Does anyone know how to fix this?

All help is appreciated. Thanks and had a good day!

+4
source share
2 answers

This error is due to the fact that findViewById only accepts int, not int and a Toolbar . It should be used as follows:

 drawerFragment.setup((DrawerLayout)findViewById(R.id.drawer_layout), toolbar); 
+3
source

just replace your line with this and the error goes away.

  drawerFragment.setUp((DrawerLayout)findViewById(R.id.drawer_layout), toolbar); 
+3
source

All Articles