Android 应用程序在真实设备上因 RecyclerView 的非法方法访问而挂起(未崩溃)

Android app hanging (not crashing) on real device with illegal method access of RecyclerView

我在我的应用程序中使用 RecyclerView,但我的应用程序只是挂起(不会退出,只是动画停止并且应用程序变得完全无响应),控制台中显示以下日志:

05-01 09:23:39.075 21296-21296/com.ulouder.ulouder D/dalvikvm: Trying to load lib /data/app-lib/com.ulouder.ulouder-1/libuLouderNative.so 0x41db4c90
05-01 09:23:39.075 21296-21296/com.ulouder.ulouder D/dalvikvm: Added shared lib /data/app-lib/com.ulouder.ulouder-1/libuLouderNative.so 0x41db4c90
05-01 09:23:39.075 21296-21296/com.ulouder.ulouder D/dalvikvm: No JNI_OnLoad found in /data/app-lib/com.ulouder.ulouder-1/libuLouderNative.so 0x41db4c90, skipping init
05-01 09:23:39.345 21296-21296/com.ulouder.ulouder I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@41dab7c8 time:89397538
05-01 09:23:39.350 2281-2319/system_process I/Timeline: Timeline: Activity_windows_visible id: ActivityRecord{430106a0 u0 com.ulouder.ulouder/com.ulouder.activities.MainActivity t19} time:89397539
05-01 09:23:42.540 21296-21741/com.ulouder.ulouder D/uLouder: [01 23 2016 09:23:42] Fired event with data: feed loaded nearby
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v7/widget/RecyclerView$ViewHolder;.isUpdated ()Z from Lcom/ulouder/viewholders/PostViewHolder;)
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: Could not find method android.support.v7.widget.RecyclerView$ViewHolder.isUpdated, referenced from method com.ulouder.viewholders.PostViewHolder.access$super
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder W/dalvikvm: VFY: unable to resolve virtual method 17616: Landroid/support/v7/widget/RecyclerView$ViewHolder;.isUpdated ()Z
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder D/dalvikvm: VFY: replacing opcode 0x6f at 0x0031
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v7/widget/RecyclerView$ViewHolder;.flagRemovedAndOffsetPosition (IIZ)V from Lcom/ulouder/viewholders/PostViewHolder;)
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: Could not find method android.support.v7.widget.RecyclerView$ViewHolder.flagRemovedAndOffsetPosition, referenced from method com.ulouder.viewholders.PostViewHolder.access$super
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder W/dalvikvm: VFY: unable to resolve virtual method 17600: Landroid/support/v7/widget/RecyclerView$ViewHolder;.flagRemovedAndOffsetPosition (IIZ)V
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder D/dalvikvm: VFY: replacing opcode 0x6f at 0x0053
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v7/widget/RecyclerView$ViewHolder;.isRemoved ()Z from Lcom/ulouder/viewholders/PostViewHolder;)
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: Could not find method android.support.v7.widget.RecyclerView$ViewHolder.isRemoved, referenced from method com.ulouder.viewholders.PostViewHolder.access$super
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder W/dalvikvm: VFY: unable to resolve virtual method 17613: Landroid/support/v7/widget/RecyclerView$ViewHolder;.isRemoved ()Z
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder D/dalvikvm: VFY: replacing opcode 0x6f at 0x0058
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v7/widget/RecyclerView$ViewHolder;.clearPayload ()V from Lcom/ulouder/viewholders/PostViewHolder;)
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: Could not find method android.support.v7.widget.RecyclerView$ViewHolder.clearPayload, referenced from method com.ulouder.viewholders.PostViewHolder.access$super
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder W/dalvikvm: VFY: unable to resolve virtual method 17595: Landroid/support/v7/widget/RecyclerView$ViewHolder;.clearPayload ()V
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder D/dalvikvm: VFY: replacing opcode 0x6f at 0x007c
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v7/widget/RecyclerView$ViewHolder;.isAdapterPositionUnknown ()Z from Lcom/ulouder/viewholders/PostViewHolder;)
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder I/dalvikvm: Could not find method android.support.v7.widget.RecyclerView$ViewHolder.isAdapterPositionUnknown, referenced from method com.ulouder.viewholders.PostViewHolder.access$super
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder W/dalvikvm: VFY: unable to resolve virtual method 17609: Landroid/support/v7/widget/RecyclerView$ViewHolder;.isAdapterPositionUnknown ()Z
05-01 09:23:42.720 21296-21296/com.ulouder.ulouder D/dalvikvm: VFY: replacing opcode 0x6f at 0x0086
...

它只是针对 RecyclerView 的许多方法进行,导致整个应用程序(或线程)在日志末尾崩溃:

05-01 09:23:42.730 21296-21296/com.ulouder.ulouder W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41873ce0)

为什么我会收到这个?这发生在 Android 4.4.4 (API 19) 的真实设备 (Samsung Galaxy S3) 上,而我的 Marshmallow 模拟器没有问题。

再一次,Android 误导了我们。与这些错误消息无关。视图绑定中存在一个实际的空指针异常,它导致整个线程崩溃,但不知何故它没有正确报告给 logcat。