개발 4일차 - 23.10.19

sooj·2023년 10월 18일

최종

목록 보기
1/6

naverMap.addOnLocationChangeListener { location ->
            Toast.makeText(this, "${location.latitude}, ${location.longitude}",
                Toast.LENGTH_SHORT).show()

            Log.d(TAG, "${location.latitude}, ${location.longitude}")
    }

[오류 메시지]

None of the following functions can be called with the arguments supplied.
makeText(Context!, CharSequence!, Int) defined in android.widget.Toast
makeText(Context!, Int, Int) defined in android.widget.Toast

makeText(Context!, CharSequence!, Int): Context 객체, 문자열 메시지 (CharSequence 또는 String), 및 지속 시간을 인수로 사용하는 함수.
makeText(Context!, Int, Int): Context 객체, 리소스 ID, 및 지속 시간을 인수로 사용하는 함수.
이 메시지는 주어진 인수와 함수 시그니처가 일치하지 않을 때 발생하는 컴파일 오류

--------
[해결]
this 는 프래그먼트라 액티비티에서 쓰는 것
프래그먼트 내에서 쓰려면 requireContext() 쓸 것

```kotlin

Toast.makeText(
                requireContext(), "${location.latitude}, ${location.longitude}",
                Toast.LENGTH_SHORT
            ).show()

참고

profile
하루하루는 성실하게 인생 전체는 되는대로

0개의 댓글