NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;
1.每当我在应用程序中刷下一张图片时,应用程序就会崩溃,我不知道出了什么问题 2.在Android 30升级后,在其正常工作之前,出现了这个问题 java.lang.NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;或者它的超类(在/system/framework/framework.jar!classes2.dex中出现'android.util.SparseArray'声明)NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;,android,kotlin,nosuchmethoderror,Android,Kotlin,Nosuchmethoderror,1.每当我在应用程序中刷下一张图片时,应用程序就会崩溃,我不知道出了什么问题 2.在Android 30升级后,在其正常工作之前,出现了这个问题 java.lang.NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;或者它的超类(在/system/framework/framework.jar!classes2.dex中出现'android.util.SparseArray'声明) 使用containsKey /** Retur
使用
containsKey
/** Returns true if the collection contains [key]. */
inline fun <T> SparseArray<T>.containsKey(key: Int) = indexOfKey(key) >= 0
/**如果集合包含[key],则返回true*/
inline fun SparseArray.containsKey(键:Int)=indexOfKey(键)>=0
我的团队负责人洞察直观方法contains(int-key)实际上是在API 30中引入的,因此它将使旧的API设备崩溃。非常新的方法不会像折旧的方法那样给你一个方便的警告,这使得它们更加危险。即使目标值低于30,Android Studio仍会毫无异议地编译contains() 参考文件给出了以下内容:
public boolean contains (int key):
Returns true if the key exists in the array. This is equivalent to indexOfKey(int) >= 0
您可以使用indexOfKey()测试等效项,尽管我个人更喜欢使用get()测试null:
/** Returns true if the collection contains [key]. */
inline fun <T> SparseArray<T>.containsKey(key: Int) = indexOfKey(key) >= 0
public boolean contains (int key):
Returns true if the key exists in the array. This is equivalent to indexOfKey(int) >= 0
get(key) != null