작성
·
160
0
alt+enter를 눌러도 임포트가 계속 안되는데 혹시 이유를 알수 있을까요? 혹시 몰라 MainActivity의 코드를 첨부하겠습니다!감사합니다!
package com.example.dice_app
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.example.dice_app.databinding.ActivityMainBinding
import java.util.*
import kotlin.random.Random.Default.nextInt
class MainActivity : AppCompatActivity() {
private lateinit var binding : ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
val diceImage1 = binding.dice1
val diceImage2 = binding.dice2
binding.diceStartBtn.setOnClickListener {
Toast.makeText(this, "주사위 GO!", Toast.LENGTH_LONG).show()
Log.d("MainActivity", Random.nextInt(1, 6).toString())
Log.d("MainActivity", Random.nextInt(1, 6).toString())
val number1 = Random.nextInt(1, 6)
val number2 = Random.nextInt(1,6)
if (number1 ==1 ){
diceImage1.setImageResource(R.drawable.dice_1)
}
else if(number1 == 2){
diceImage1.setImageResource(R.drawable.dice_2)
}
else if(number1 == 3){
diceImage1.setImageResource(R.drawable.dice_3)
}
else if(number1 == 4){
diceImage1.setImageResource(R.drawable.dice_4)
}
else if(number1 == 5){
diceImage1.setImageResource(R.drawable.dice_5)
}
else {
diceImage1.setImageResource(R.drawable.dice_6)
}
if (number2 ==1 ){
diceImage2.setImageResource(R.drawable.dice_1)
}
else if(number2 == 2){
diceImage2.setImageResource(R.drawable.dice_2)
}
else if(number2 == 3){
diceImage2.setImageResource(R.drawable.dice_3)
}
else if(number2 == 4){
diceImage2.setImageResource(R.drawable.dice_4)
}
else if(number2 == 5){
diceImage2.setImageResource(R.drawable.dice_5)
}
else {
diceImage2.setImageResource(R.drawable.dice_6)
}
}
}
}
답변 1
2
안녕하세요 import부분에
import java.util.*
이 부분 삭제하시고
import kotlin.random.Random
이 부분 추가해보시겠어요?
random import할 때 다른 패키지를 임포트 하신 것 같습니다 :)
오! 감사합니다 저도 같은 문제를 겯고있었는데 해결이 되었네요!