Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Can't find Drawable Resource

Tags:

android

package com.sarham.kabs.fruity;

import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener{

    private DrawerLayout drawerLayout;
    private ListView listView;
    private String[] planets;
    private ActionBarDrawerToggle drawerListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout);
        listView = (ListView)findViewById(R.id.drawerListView);
        planets = getResources().getStringArray(R.array.planets);
        listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, planets));
        listView.setOnItemClickListener(this);
        drawerListener = new ActionBarDrawerToggle(this, drawerLayout, R.mipmap.ic_drawer, R.string.drawer_open, R.string.drawer_close){
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                Toast.makeText(MainActivity.this,"Drawer Open", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                Toast.makeText(MainActivity.this, "Drawer Closed", Toast.LENGTH_LONG).show();
            }
        };
        drawerLayout.setDrawerListener(drawerListener);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, planets[position]+" Was selected", Toast.LENGTH_LONG).show();
        selectItem(position);
    }
    public void selectItem(int position){
        listView.setItemChecked(position, true);
        setTitle(planets[position]);
    }
    public void setTitle(String title){
        getSupportActionBar().setTitle(title);
    }
}

I'm working on a project in android studio, I'm trying to put the navigation drawer icon but I receive this error: 'cannot find symbol R.mipmap.if_drawer', I've tried placing it in the drawable but the same error is thrown for symbol 'R.drawable. ic_drawer'

After cleaning and rebuliding, I get the following message:

Error:(32, 26) error: no suitable constructor found for ActionBarDrawerToggle(MainActivity,DrawerLayout,int,int,int) constructor ActionBarDrawerToggle.ActionBarDrawerToggle(Activity,Toolbar,DrawerLayout,T,int,int) is not applicable (cannot instantiate from arguments because actual and formal argument lists differ in length) constructor ActionBarDrawerToggle.ActionBarDrawerToggle(Activity,DrawerLayout,Toolbar,int,int) is not applicable (actual argument int cannot be converted to Toolbar by method invocation conversion) constructor ActionBarDrawerToggle.ActionBarDrawerToggle(Activity,DrawerLayout,int,int) is not applicable (actual and formal argument lists differ in length) where T is a type-variable: T extends Drawable,DrawerToggle declared in constructor ActionBarDrawerToggle(Activity,Toolbar,DrawerLayout,T,int,int)

like image 755
Kabs Avatar asked Mar 21 '15 10:03

Kabs


People also ask

Where is the drawable folder in Android Studio?

In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.

What is drawable resource in android?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.

Which function is used to load a drawable image resource?

Drawable myImage = ResourcesCompat. getDrawable(res, R. drawable. my_image, null);

How do I import a drawable file?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.


2 Answers

Please Clean Your Project & Rebuild .

Build > Clean Project Then Build > Rebuild Project

like image 190
IntelliJ Amiya Avatar answered Oct 07 '22 15:10

IntelliJ Amiya


on checking through the errors the IDE was throwing and suggestions it gave, the following was what I learnt: there are two constructors for the ActionBarDrawerToggle:

  1. ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int drawerOpenContentDescription, int drawerClosedContentDescription)
  2. ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerOpenContentDescription, int drawerClosedContentDescription)

I used the 2nd constructor with 4 parameters and the navigation drawer worked fine without placing the 'ic_drawer' icon, instead, it is replaced with a back arrow.

like image 41
Kabs Avatar answered Oct 07 '22 16:10

Kabs