Any suggestion on how to troubleshoot this?
Asked
Active
Viewed 982 times
3

Stianhn
- 275
- 2
- 14
-
try `.single().digitToInt()` – Ananiya Jemberu May 07 '21 at 14:52
-
I thoght yoou should be able to use toInt()? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-int.html – Stianhn May 07 '21 at 15:01
-
yeah I know incase you missed the file I thought it would be possible solution and can you show up the library you declared in gradle ? – Ananiya Jemberu May 07 '21 at 15:11
-
Make sure Kotlin plugin is up to date in the IDE settings. Refresh the Gradle build and check for errors. Rebuild the project. – Tenfour04 May 07 '21 at 15:34
-
There are some [changes to the character conversions](https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/char-int-conversions.md) in [Kotlin 1.5](https://kotlinlang.org/docs/whatsnew15.html#stable-char-to-integer-conversion-api); in particular, `Char.toInt()` is deprecated. However, `String.toInt()` is still around (as you can verify in the REPL). – gidds May 07 '21 at 18:37
-
Seeing latest Kotlin documentation on `String` the only available method is `toIntOrNull` https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/ – Boris Strandjev May 10 '21 at 07:10
-
Yes, but this is not showing as an alternative either :/ – Stianhn May 11 '21 at 08:57
-
@BorisStrandjev `String.toInt()` still exists, it's in `kotlin.text`: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-int.html – Joffrey May 12 '21 at 19:36
-
1I agree with @Joffrey. @Stianhn, have you tried compiling `"1".toInt()`, even if your IDE highlighting indicates that it will not work? – ordonezalex May 12 '21 at 22:36
2 Answers
3
This could be an IntelliJ issue. Does the program compile with Gradle?
Assuming the former, try re-installing and/or updating the Kotlin plugin for IntelliJ. Also, try clearing caches via File > Invalidate Caches ... > Invalidate and Restart

Vadim Hagedorn
- 159
- 1
- 12
-3
If you are planning on changing that digit or using it more than once, I would recommend making it a val or var. And the .toInt is available.
fun main() {
var number = "1"
val printThis = number.toInt()
println(printThis)
}

Umar zzstu Syed
- 13
- 1
- 7
-
5The OP is using a simple example just to illustrate that the function is missing. – Tenfour04 May 07 '21 at 15:33