romannurik / AndroidAssetStudio

A set of web-based tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error inflating class ImageView - Unable to find resource

zjamshidi opened this issue · comments

I generated icons using this great tool and put it in "res" folder of my app. Today I received some crashes with the following logs:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{ui.MainActivity}: android.view.InflateException: Binary XML file line #39: Error inflating class ImageView
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Caused by android.view.InflateException: Binary XML file line #39: Error inflating class ImageView
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
       at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
       at ui.MainActivity.onCreate(MainActivity.java:215)
       at android.app.Activity.performCreate(Activity.java:5937)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)


Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0800cf
       at android.content.res.Resources.getResourceName(Resources.java:2026)
       at android.content.res.Resources.loadDrawableForCookie(Resources.java:2390)
       at android.content.res.Resources.loadDrawable(Resources.java:2330)
       at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
       at android.widget.ImageView.<init>(ImageView.java:146)
       at android.widget.ImageView.<init>(ImageView.java:135)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
       at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
       at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
       at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
       at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
       at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
       at ui.MainActivity.onCreate(MainActivity.java:215)
       at android.app.Activity.performCreate(Activity.java:5937)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
       at android.app.ActivityThread.access$800(ActivityThread.java:144)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5221)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

when I checked the R.java file the resource id is for ic_action_share, which already exists in drawable folders:
image

and here is how I used the image:

     <ImageView
                android:id="@+id/app_share_menu"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:background="@drawable/btn_bg_ripple"
                android:src="@drawable/ic_action_share" />

The app works well on my test devices but some users have problems with it. Do you have any suggestions how to fix it?

Hm, I really don't see how the tool can be at fault here... have you tried using other PNGs? I get the sense there's something in your code..