找不到类'android.graphics.drawable.RippleDrawable'。

9

Android应用程序突然关闭并在logcat中给出以下错误。

01-22 00:33:58.470 8193-8193/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
01-22 00:34:00.010 1173-1173/? E/MyTag: updateClock : 12:34
01-22 00:34:00.015 1173-1173/? E/MyTag: updateClock : 12:34 AM
01-22 00:34:00.051 1173-1173/? E/MyTag: updateClock : 12:34 AM
01-22 00:34:00.080 1432-1432/? E/ActionIcon: time changed: time = 20170122T003400Asia/Calcutta(0,21,19800,0,1485025440)
01-22 00:34:00.086 8210-8210/? E/Zygote: Zygote:  error closing descriptor
                                         libcore.io.ErrnoException: close failed: EBADF (Bad file number)
                                             at libcore.io.Posix.close(Native Method)
                                             at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
                                             at com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:221)
                                             at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
                                             at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
                                             at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:713)
                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:649)
                                             at dalvik.system.NativeStart.main(Native Method)

请查看此帖子:点击这里 - NightFury
2
你解决了你的问题吗?我知道已经过去5个月了,但我现在也面临同样的问题。 - Simon
1个回答

2

对于我来说,问题出在我使用的color-selector可绘制对象上,我将其用作ImageViewtint值。这导致了在API 19上崩溃(我认为所有API < 21的设备都会出现此问题)。

有问题的代码

<ImageView
    android:id="@+id/icon"
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:layout_gravity="center"
    android:src="@drawable/ic_music_note_white_24dp"
    android:tint="@color/color_bottom_navigation_item" />

color_bottom_navigation_item.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#00CCF0" android:state_selected="true" />
    <item android:color="#75848C" />
</selector>

解决方案

从XML中删除android:tint属性,并以以下方式在程序中设置:

ImageView icon = findViewById(R.id.icon);
ColorStateList tint = getResources().getColorStateList(R.color.color_bottom_navigation_item);

Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_music_note_white_24dp);
drawable = DrawableCompat.wrap(drawable).mutate();
DrawableCompat.setTintList(drawable, tint);
icon.setImageDrawable(drawable);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接