android – Cannot resolve symbol @drawable/ic_launcher-ThrowExceptions

Exception or error:

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>
How to solve:

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.

###

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

Leave a Reply

Your email address will not be published. Required fields are marked *