前提・実現したいこと
Android Studio(kotlin)でアプリの作成中に、以下のエラーがでる。
参照している、参考書:Kotlin対応 初めてのAndroidプログラミング第3版
発生している問題・エラーメッセージ
Expecting member declaration Expecting member declaration Expecting member declaration Expecting member declaration Expecting member declaration Expecting member declaration Unexpected tokens (use ';' to separate expressions on the same line) Unexpected tokens (use ';' to separate expressions on the same line) Unexpected tokens (use ';' to separate expressions on the same line) Expecting member declaration Expecting member declaration Expecting member declaration Expecting member declaration Conflicting overloads: public final fun <no name provided>(): Unit defined in com.example.janken.resultactivity, public final fun <no name provided>(): Unit defined in com.example.janken.resultactivity Function declaration must have a name Unresolved reference: int Unresolved reference: comhand Unresolved reference: myHand
該当のソースコード
//(kotlin) package com.example.janken import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_resultactivity.* class resultactivity : AppCompatActivity() { val gu=0 val choki=0 val pa=0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_resultactivity) val id=intent.getIntExtra("MY_HAND",0) val myHand:int myHand=when(id) { R.id.gu -> { myHandImage.setImageResource(R.drawable.gu) gu } R.id.choki -> { myHandImage.setImageResource(R.drawable.choki) choki } R.id.pa -> { myHandImage.setImageResource(R.drawable.pa) pa } else->gu } //コンピュータの手を決める val comHand=(Math.random()*3).toInt() when(comHand){ gu->comHandImage.setImageResource(R.drawable.com_gu) choki->comHandImage.setImageResource(R.drawable.com_choki) pa->comHandImage.setImageResource(R.drawable.com_pa) } } /*when(id){ R.id.gu -> myHandImage.setImageResource(R.drawable.gu) R.id.choki -> myHandImage.setImageResource(R.drawable.choki) R.id.pa -> myHandImage.setImageResource(R.drawable.pa) } */ //勝敗を判定 val gameResult=(comhand-myHand+3)%3 when(gameResult) { 0 ->resultLabel.setText(R.string.result_draw)//引き分け 1 ->resultLabel.setText(R.string.result_win) //勝ち 2 ->resultLabel.setText(R.string.result_lose) //負け } backButton.setOnClickListener{finish()}
試したこと
調べてみましたが、いまいちよくわかりません。
よろしくお願いいたします。
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。