27

I have an ImageView in my layout, see below code. When I'm trying to set the src attribute to be my launcher icon, I get the following error:

Cannot resolve symbol '@drawable/ic_launcher'

ic_launcer.png is added to my drawables folder, see below image. Why can I not reference my image in my ImageView?

Project structure:

Project structure

Layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_weight="1"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:src="@drawable/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Marcus
  • 6,697
  • 11
  • 46
  • 89

2 Answers2

50

Change(you have no drawable folders):

@drawable/ic_launcher

To(you are using mipmap folders):

@mipmap/ic_launcher

mipmaps - used for icons only - mipmap vs drawable folders

drawables - used for images other than icons

According to this Google blogpost:

It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.

Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
4

your drawable are inside mipmap, which should be used to app-launcher. If you want to use it as drawable you should copy those inside one of the drawable/ folders

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I see that now, must have been changed when I updated Android Studio. Is there any easy way to copy them to my (just created) drawable folder? `ctrl + c` and `ctrl + v` doesn't seem to work inside AS. Do I have to do it with file explorer? – Marcus Mar 24 '15 at 21:29
  • 1
    it works on mac. If you are not on windows, use the shell.. it is the quickest way – Blackbelt Mar 24 '15 at 21:30
  • @Marcus, [shift] + [f6] to quickly rename the folders. Mipmaps are the new way of doing drawables. – Jared Burrows Mar 24 '15 at 21:32
  • 2
    I ended up referencing it as `@mipmap/ic_launcher` as suggested by @JaredBurrows. +1 for your efforts tho, thanks. – Marcus Mar 24 '15 at 21:33
  • check the documentation about `mipmap`. its behavior is slightly different from `drawable`. You are welcome – Blackbelt Mar 24 '15 at 21:34
  • @JaredBurrows Not entirely true! Mipmap are the new way of doing launchers and other resources you might need in other densities. Mostly just launchers. – Lamorak Mar 24 '15 at 21:34
  • I will remember that, thanks for the help! Is it considered wrong to add my other drawables to the `mipmap` folder? As @Blackbelt stated, "mipmap [...] should be used to for app-launcher" @JaredBurrows – Marcus Mar 24 '15 at 21:35
  • @Lamorak That is true but he **only** has launchers in his photo from his question. – Jared Burrows Mar 24 '15 at 21:35
  • 1
    It is not considered wrong, you'll just get different behavior. Basically best fitting resource will be chosen from `mipmap` folders for your ImageView, instead of picking the image marked for your density from corresponding `drawable` folder. – Lamorak Mar 24 '15 at 21:41