작성
·
322
0
앱 실행시키면 이런 오류가 나요... 강의 코드와 비교도 해보고 저 스스로 최대한 찾아보려고했지만 못 찾겠어요 도와주세요
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#008000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="100dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textColor="@color/black"
android:layout_margin="20dp"
android:gravity="center"
android:textStyle="bold"
android:text="인생은 주사위 한방에 가는거 아니겠습니까?!"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:weightSum="2">
<ImageView
android:id="@+id/dice1"
android:src="@drawable/dice_1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_weight="1"/>
<ImageView
android:id="@+id/dice2"
android:src="@drawable/dice_1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/diceStartBtn"
android:text="인생 고고"
android:backgroundTint="@color/black"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="50dp"/>
</LinearLayout>
</layout>
package com.johnson.randomdice_app
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.johnson.randomdice_app.databinding.ActivityMainBinding
import kotlin.random.Random
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, "굴립니다", 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)
}
}
}
}