简体   繁体   中英

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

What is the problem? The IDE itself tells you, an Int was expected but you are passing a String.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM