1

On some devices there is no problem but on some such exception appears when opening src of ImageView.

The stack trace looks like this:

    java.lang.RuntimeException: Unable to start activity 
    ComponentInfo{pl.jawegiel.endlessblow/pl.jawegiel.endlessblow.activities.MainActivity}: 
android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class 
ImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666) at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) at android.app.ActivityThread.-
wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) at 
android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at 
android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native 
Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: android.view.InflateException: 
Binary XML file line #11: Binary XML file line #11: Error inflating class ImageView Caused by: 
android.view.InflateException: Binary XML file line #11: Error inflating class ImageView Caused by: 
android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f0800cd 
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0800cd at 
android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:228) at 
android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:687) at 
android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at 
android.content.res.Resources.loadDrawable(Resources.java:858) at 
android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.widget.ImageView.
(ImageView.java:162) at android.widget.ImageView.(ImageView.java:150) at 
androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:74) at 
androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:69) at 
androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:199) at 
androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:119) at 
androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1551) at 
androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1602) at 
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769) at 
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at 
android.view.LayoutInflater.rInflate(LayoutInflater.java:858) at 
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at 
android.view.LayoutInflater.inflate(LayoutInflater.java:518) at 
android.view.LayoutInflater.inflate(LayoutInflater.java:426) at 
android.view.LayoutInflater.inflate(LayoutInflater.java:377) at 
androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at 
androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at 
pl.jawegiel.endlessblow.activities.MainActivity.onCreate(MainActivity.java:50) at 
android.app.Activity.performCreate(Activity.java:6682) at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619) at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) at android.app.ActivityThread.-
wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) at 
android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at 
android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native 
Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 

MainActivity.java:50 looks like this:

setContentView(R.layout.activity_main);

ImageView that causes problem looks like this:

    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/splash2"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:contentDescription="TODO" />

this splash2.png is located in res\drawable, res\drawable-hdpi, res\drawable-mdpi, res\drawable-xhdpi, res\drawable-xxhdpi and res\drawable-xxxhdpi so I guess in correct folders. So how to solve that?

Thank you in advance!

Qbi
  • 445
  • 4
  • 13
  • Check to see if there is some problem with the naming of your *.png file. then see if you have any other issue in the layout because it may create misleading error and in the end, one cache invalidate and restart can be performed and rebuild the project.(https://i.stack.imgur.com/3Gibe.png) – MihaiBC Feb 19 '21 at 11:39
  • How to check if there is a problem with naming? – Qbi Feb 19 '21 at 11:58
  • try to rename it and see if there are no white spaces and the extensions is ok – MihaiBC Feb 19 '21 at 12:00
  • There is no problem with name of .png. Maybe the solution would be to move this .png from drawable to mipmap? – Qbi Feb 19 '21 at 12:03
  • No, the mipmap should be only used for the app icon. – MihaiBC Feb 19 '21 at 12:06
  • Try to invalidate the cache and restart and then build your project again. – MihaiBC Feb 19 '21 at 12:06
  • The problem is I do not know yet if this helped because those are stacktrases from client's phones. I need to upload to Google Play and wait for possible error logs comming to my email. But if you are already here. Can there be any other possible solutions for this in case if none of your solution works? – Qbi Feb 19 '21 at 12:16

1 Answers1

0

You may be able to solve this problem with a more generalistic approach: Try using scalable vector graphics (SVG) instead of .PNG-images. VectorDrawable is more flexible if you need to match different screen resolutions.

PNGs can be transformed into scalable vector graphics with Inkscape or online PNG converter (https://convertio.co/de/png-svg/)

After that you can create a new VectorDrawable by loading the SVG. VectorDrawables can be assigned with app:srcCompat="@drawable/ic_VectorDrawableName"

Documentation:

A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability. It can be scaled without loss of display quality, which means the same file is resized for different screen densities without loss of image quality. This results in smaller APK files and less developer maintenance. You can also use vector images for animation by using multiple XML files instead of multiple images for each display resolution.

VectorDrawable also requires much less RAM than .PNG.

You may find the cause of your errors in this thread:

Resources$NotFoundException drawable-xhdpi from drawable resource

Dorian Feyerer
  • 258
  • 5
  • 14