Search code examples
androidandroid-studioandroid-drawableandroidx

error: incompatible types: int cannot be converted to Toolbar R.drawable.ic_drawer & cannot find symbol "mDrawerToggle = new ActionBarDrawerToggle("


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.multidex.MultiDex;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.drawerlayout.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

and error this "error: incompatible types: int cannot be converted to Toolbar R.drawable.ic_drawer & cannot find symbol "mDrawerToggle = new ActionBarDrawerToggle("

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
        this,                  /* host Activity */
        mDrawerLayout,         /* DrawerLayout object */
        R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
        R.string.drawer_open,  /* "open drawer" description */
        R.string.drawer_close  /* "close drawer" description */
        ) {

Solution

  • You are using this constructor:

    ActionBarDrawerToggle(Activity activity,
              DrawerLayout drawerLayout, 
              Toolbar toolbar, 
              int openDrawerContentDescRes, 
              int closeDrawerContentDescRes)
    

    The issue is with

    R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
    

    You have to pass the Toolbar.