Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;_Android_Kotlin_Nosuchmethoderror - Fatal编程技术网

NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;

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

1.每当我在应用程序中刷下一张图片时,应用程序就会崩溃,我不知道出了什么问题

2.在Android 30升级后,在其正常工作之前,出现了这个问题

java.lang.NoSuchMethodError:没有虚拟方法包含(I)Landroid/util/SparseArray类中的Z;或者它的超类(在/system/framework/framework.jar!classes2.dex中出现'android.util.SparseArray'声明)


使用
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