質問編集履歴
2
クラス全体を追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
kotlinでAndroid Studioのエラー"Expecting member declaration"
|
1
|
+
kotlinでAndroid Studioのエラー"Expecting member declaration"等
|
body
CHANGED
@@ -1,11 +1,29 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
Android Studio(kotlin)でアプリの作成中に、
|
3
|
+
Android Studio(kotlin)でアプリの作成中に、以下のエラーがでる。
|
4
|
+
参照している、参考書:Kotlin対応 初めてのAndroidプログラミング第3版
|
4
5
|
|
5
6
|
### 発生している問題・エラーメッセージ
|
6
7
|
|
7
8
|
```
|
8
9
|
Expecting member declaration
|
10
|
+
Expecting member declaration
|
11
|
+
Expecting member declaration
|
12
|
+
Expecting member declaration
|
13
|
+
Expecting member declaration
|
14
|
+
Expecting member declaration
|
15
|
+
Unexpected tokens (use ';' to separate expressions on the same line)
|
16
|
+
Unexpected tokens (use ';' to separate expressions on the same line)
|
17
|
+
Unexpected tokens (use ';' to separate expressions on the same line)
|
18
|
+
Expecting member declaration
|
19
|
+
Expecting member declaration
|
20
|
+
Expecting member declaration
|
21
|
+
Expecting member declaration
|
22
|
+
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
|
23
|
+
Function declaration must have a name
|
24
|
+
Unresolved reference: int
|
25
|
+
Unresolved reference: comhand
|
26
|
+
Unresolved reference: myHand
|
9
27
|
|
10
28
|
```
|
11
29
|
|
@@ -15,14 +33,66 @@
|
|
15
33
|
```ここに言語名を入力
|
16
34
|
//(kotlin)
|
17
35
|
|
36
|
+
package com.example.janken
|
37
|
+
|
38
|
+
import androidx.appcompat.app.AppCompatActivity
|
39
|
+
import android.os.Bundle
|
40
|
+
import kotlinx.android.synthetic.main.activity_resultactivity.*
|
41
|
+
|
42
|
+
class resultactivity : AppCompatActivity() {
|
43
|
+
|
44
|
+
val gu=0
|
45
|
+
val choki=0
|
46
|
+
val pa=0
|
47
|
+
|
48
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
49
|
+
super.onCreate(savedInstanceState)
|
50
|
+
setContentView(R.layout.activity_resultactivity)
|
51
|
+
val id=intent.getIntExtra("MY_HAND",0)
|
52
|
+
|
53
|
+
val myHand:int
|
54
|
+
myHand=when(id) {
|
55
|
+
R.id.gu -> {
|
56
|
+
myHandImage.setImageResource(R.drawable.gu)
|
57
|
+
gu
|
58
|
+
}
|
59
|
+
|
60
|
+
R.id.choki -> {
|
61
|
+
myHandImage.setImageResource(R.drawable.choki)
|
62
|
+
choki
|
63
|
+
}
|
64
|
+
R.id.pa -> {
|
65
|
+
myHandImage.setImageResource(R.drawable.pa)
|
66
|
+
pa
|
67
|
+
}
|
68
|
+
else->gu
|
69
|
+
}
|
70
|
+
//コンピュータの手を決める
|
71
|
+
val comHand=(Math.random()*3).toInt()
|
72
|
+
when(comHand){
|
73
|
+
gu->comHandImage.setImageResource(R.drawable.com_gu)
|
74
|
+
choki->comHandImage.setImageResource(R.drawable.com_choki)
|
75
|
+
pa->comHandImage.setImageResource(R.drawable.com_pa)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
/*when(id){
|
79
|
+
R.id.gu -> myHandImage.setImageResource(R.drawable.gu)
|
80
|
+
R.id.choki -> myHandImage.setImageResource(R.drawable.choki)
|
81
|
+
R.id.pa -> myHandImage.setImageResource(R.drawable.pa)
|
82
|
+
}
|
83
|
+
*/
|
84
|
+
//勝敗を判定
|
18
|
-
val gameResult=
|
85
|
+
val gameResult=(comhand-myHand+3)%3
|
19
86
|
when(gameResult)
|
20
87
|
{
|
21
|
-
0->resultLabel.setText(R.string.result_draw)//引き分け
|
88
|
+
0 ->resultLabel.setText(R.string.result_draw)//引き分け
|
22
|
-
1->resultLabel.setText(R.string.result_win) //勝ち
|
89
|
+
1 ->resultLabel.setText(R.string.result_win) //勝ち
|
23
|
-
2->resultLabel.setText(R.string.result_lose) //負け
|
90
|
+
2 ->resultLabel.setText(R.string.result_lose) //負け
|
24
91
|
|
25
92
|
}
|
93
|
+
backButton.setOnClickListener{finish()}
|
94
|
+
|
95
|
+
|
26
96
|
```
|
27
97
|
|
28
98
|
### 試したこと
|
1
文言の修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
kotlinでAndroid Studioの
|
1
|
+
kotlinでAndroid Studioのエラー"Expecting member declaration"
|
body
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
```
|
8
8
|
Expecting member declaration
|
9
9
|
|
10
|
-
Unexpected tokens (use ';' to separate expressions on the same line)
|
11
10
|
```
|
12
11
|
|
13
12
|
### 該当のソースコード
|
@@ -27,6 +26,8 @@
|
|
27
26
|
```
|
28
27
|
|
29
28
|
### 試したこと
|
29
|
+
調べてみましたが、いまいちよくわかりません。
|
30
|
+
よろしくお願いいたします。
|
30
31
|
|
31
32
|
ここに問題に対して試したことを記載してください。
|
32
33
|
|