EditText 의 수치값을 Int 변수로 가져오려는 아주 간단한 코드에서 자꾸 Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 에러가 발생했다.
코드는 다음과 같다.
val n:Int = binding.editBunja.text.toInt()
edit_bunja 에서 text 를 가져와서 toInt 로 정수형으로 바꾸려고 하는데, 왜 에러가 발생하는 걸까 한참을 고민했다.
결론은, editBunja.text 가 String 이 아니라, Editable 이라는 다른 type의 값이어서, 이걸 다시 String 으로 먼저 바꿔 주어야 했다.
val n:Int = binding.editBunja.text.toString().toInt()
아직 코틀린이 익숙하지가 않다.
728x90
'프로그래밍 > Android' 카테고리의 다른 글
코틀린 String.toInt() Unresolved reference (0) | 2022.01.03 |
---|---|
Android : The emulator process for AVD Pixel_XL has terminated. (0) | 2021.12.17 |
adb.exe not a valid win32 application. CreateProcess error (0) | 2021.12.12 |
Volley : GET request 에서는getParams 는 불리지 않는다. (0) | 2021.12.06 |
[ANDROID] java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed (0) | 2020.07.20 |
[Android] Error type 3 Activity class does not exist. (0) | 2020.02.20 |