简体   繁体   English

类型不匹配:推断类型为 String 但预期为 Int,Kotlin

[英]Type mismatch: inferred type is String but Int was expected , Kotlin

在此处输入图像描述

Task:app:compileDebugKotlin FAILED任务:应用程序:编译调试科特林失败

Type mismatch: inferred type is String but Int was expected类型不匹配:推断类型为 String 但应为 Int

What is the problem?问题是什么? The IDE itself tells you, an Int was expected but you are passing a String. IDE 本身告诉你,一个 Int 是预期的,但你传递的是一个字符串。

To get values ​​from resources, for example, strings, themes, etc... you need to pass an Int or id of the resource, which is obtained by doing从资源中获取值,例如字符串、主题等...需要传入资源的一个Int或者id,通过doing获取

R.id.your_resource

So looking at your code:所以看看你的代码:

val InterstitialId = dataSnapshot.child("interstitial_id").value.toString()

This line will return a string when you call the .toString method, 2 lines below you are passing this variable to a .getString and according to the documentation getString() expects an Int not a String.当您调用.toString方法时,此行将返回一个字符串,下面的 2 行将此变量传递给.getString并且根据文档getString()需要一个 Int 而不是 String。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型不匹配:推断类型是字符串? 但预计字符串 kotlin - Type mismatch: inferred type is String? but String was expected kotlin 类型不匹配:推断类型是String,但是在kotlin中预计会出现Charset - Type mismatch: inferred type is String but Charset was expected in kotlin 类型不匹配:推断的类型是String? 但是字符串是预期的 - Type mismatch: inferred type is String? but String was expected Kotlin推断出类型不匹配 - Kotlin inferred type mismatch Kotlin:类型不匹配:推断类型为 String 但上下文是预期的 -(kotlin 类特定错误中的通知通道) - Kotlin: Type mismatch: inferred type is String but Context was expected -(notification channel in kotlin-class specific error) Android Kotlin - viewBinding 类型不匹配:推断的类型是 DrawerLayout 但 ConstraintLayout 是预期的 - Android Kotlin - viewBinding Type mismatch: inferred type is DrawerLayout but ConstraintLayout was expected 类型不匹配:推断的类型是上下文? 但希望有上下文-Kotlin - Type mismatch: inferred type is Context? but Context was expected - Kotlin Kotlin:类型不匹配:推断的类型是 Intent? 但意图是预期的 - Kotlin : Type mismatch: inferred type is Intent? but Intent was expected Kotlin - 类型不匹配:推断的类型是 Unit,但 Intent 是预期的 - Kotlin - Type mismatch: inferred type is Unit but Intent was expected Kotlin类型不匹配:推断类型是View! 但TextView是预料之中的 - Kotlin Type mismatch: inferred type is View! but TextView was expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM