Reputation: 17
Having an error with Android Studios (Kotlin)
Error:
e: Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.
fun devId(): Any {
var str = Build.CPU_ABI
if (Build.VERSION.SDK_INT >= 21) {
var i = 0
val hashSet = HashSet(listOf(arrayOf("armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64")))
val strArr = Build.SUPPORTED_ABIS
val length = strArr.size
while (true) {
if (i >= length) { break }
val str2 = strArr[i]
if (hashSet.contains(str2)) {
str = str2
break
}
i++
}
}
return println(Build.BOARD + Build.BRAND + str + Build.DEVICE + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT)
}
Upvotes: 1
Views: 4274
Reputation: 837
The problem is in hashSet.contains(str2)
. This expression is always false. Because hashSet
type is HashSet<Array<String>>
but str2
is String
You could pass to function contains
only Array<String>
Looks like you could rewrite yours code as:
fun devId() {
val str = if (Build.VERSION.SDK_INT >= 21) {
Build.SUPPORTED_ABIS
.firstOrNull { it in setOf("armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64") }
?: Build.CPU_ABI
} else Build.CPU_ABI
return println(Build.BOARD + Build.BRAND + str + Build.DEVICE + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT)
}
Upvotes: 3