
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
2-4를 강의에 따라, 진행하여, 회차별 로또 번호를 받아서 실행까지 되는 것을 확인 후, 프로그램 종료 후 재실행 과정에서
val data = RetrofitInstance.api.getLottoNumber(num = 1104)
suspend function call이라는 알람이 발생 후 그 뒤에 문을 실행하지 못하는 것 같습니다.
발생원인과 해결밥안을 알 수 있을까요?
감사합니다

작성한 코드 및 에러 메세지
package com.example.lotto
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
//import com.example.lotto.R
import com.example.lotto.api.RetrofitInstance
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
//import kotlin.random.Random
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val numberOne = findViewById<TextView>(R.id.number_one)
val numberTwo = findViewById<TextView>(R.id.number_two)
val numberThree = findViewById<TextView>(R.id.number_three)
val numberFour = findViewById<TextView>(R.id.number_four)
val numberFive = findViewById<TextView>(R.id.number_five)
val numberSix = findViewById<TextView>(R.id.number_six)
val numberBonus = findViewById<TextView>(R.id.number_bonus)
val randomButton = findViewById<Button>(R.id.random_button)
randomButton.setOnClickListener {
// val winNumbers = generateLottoNumbers().sorted()
CoroutineScope(Dispatchers.IO).launch {
val data = RetrofitInstance.api.getLottoNumber(num = 1104)
Log.d("getLottoNumber", "data: $data")
}
/*
val winNumbers =
println("lottoWinner: $winNumbers")
numberOne.text = winNumbers[0].toString()
numberTwo.text = winNumbers[1].toString()
numberThree.text = winNumbers[2].toString()
numberFour.text = winNumbers[3].toString()
numberFive.text = winNumbers[4].toString()
numberSix.text = winNumbers[5].toString()
numberBonus.text = winNumbers[6].toString()
*/
// val winNumbersView = listOf(numberOne, numberTwo, numberThree, numberFour, numberFive, numberSix, numberBonus)
// winNumbers.mapIndexed { index, number -> winNumbersView[index].text = number.toString() }
}
}
/*
private fun generateLottoNumbers(): Set<Int> {
val numbers = mutableSetOf<Int>()
while (numbers.size < 7) {
val randomNumber = Random.nextInt(1, 46) // 1부터 45까지의 숫자 중 랜덤 선택
numbers.add(randomNumber)
}
return numbers
}
*/
}
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
