質問編集履歴

2

クラス全体を追加

2019/11/19 06:49

投稿

reguosu22
reguosu22

スコア9

test CHANGED
@@ -1 +1 @@
1
- kotlinでAndroid Studioのエラー"Expecting member declaration"
1
+ kotlinでAndroid Studioのエラー"Expecting member declaration"
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
 
4
4
 
5
- Android Studio(kotlin)でアプリの作成中に、
5
+ Android Studio(kotlin)でアプリの作成中に、以下のエラーがでる。
6
+
7
+ 参照している、参考書:Kotlin対応 初めてのAndroidプログラミング第3版
6
8
 
7
9
 
8
10
 
@@ -14,6 +16,40 @@
14
16
 
15
17
  Expecting member declaration
16
18
 
19
+ Expecting member declaration
20
+
21
+ Expecting member declaration
22
+
23
+ Expecting member declaration
24
+
25
+ Expecting member declaration
26
+
27
+ Expecting member declaration
28
+
29
+ Unexpected tokens (use ';' to separate expressions on the same line)
30
+
31
+ Unexpected tokens (use ';' to separate expressions on the same line)
32
+
33
+ Unexpected tokens (use ';' to separate expressions on the same line)
34
+
35
+ Expecting member declaration
36
+
37
+ Expecting member declaration
38
+
39
+ Expecting member declaration
40
+
41
+ Expecting member declaration
42
+
43
+ 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
44
+
45
+ Function declaration must have a name
46
+
47
+ Unresolved reference: int
48
+
49
+ Unresolved reference: comhand
50
+
51
+ Unresolved reference: myHand
52
+
17
53
 
18
54
 
19
55
  ```
@@ -32,22 +68,126 @@
32
68
 
33
69
 
34
70
 
71
+ package com.example.janken
72
+
73
+
74
+
75
+ import androidx.appcompat.app.AppCompatActivity
76
+
77
+ import android.os.Bundle
78
+
79
+ import kotlinx.android.synthetic.main.activity_resultactivity.*
80
+
81
+
82
+
83
+ class resultactivity : AppCompatActivity() {
84
+
85
+
86
+
87
+ val gu=0
88
+
89
+ val choki=0
90
+
91
+ val pa=0
92
+
93
+
94
+
95
+ override fun onCreate(savedInstanceState: Bundle?) {
96
+
97
+ super.onCreate(savedInstanceState)
98
+
99
+ setContentView(R.layout.activity_resultactivity)
100
+
101
+ val id=intent.getIntExtra("MY_HAND",0)
102
+
103
+
104
+
105
+ val myHand:int
106
+
107
+ myHand=when(id) {
108
+
109
+ R.id.gu -> {
110
+
111
+ myHandImage.setImageResource(R.drawable.gu)
112
+
113
+ gu
114
+
115
+ }
116
+
117
+
118
+
119
+ R.id.choki -> {
120
+
121
+ myHandImage.setImageResource(R.drawable.choki)
122
+
123
+ choki
124
+
125
+ }
126
+
127
+ R.id.pa -> {
128
+
129
+ myHandImage.setImageResource(R.drawable.pa)
130
+
131
+ pa
132
+
133
+ }
134
+
135
+ else->gu
136
+
137
+ }
138
+
139
+ //コンピュータの手を決める
140
+
141
+ val comHand=(Math.random()*3).toInt()
142
+
143
+ when(comHand){
144
+
145
+ gu->comHandImage.setImageResource(R.drawable.com_gu)
146
+
147
+ choki->comHandImage.setImageResource(R.drawable.com_choki)
148
+
149
+ pa->comHandImage.setImageResource(R.drawable.com_pa)
150
+
151
+ }
152
+
153
+ }
154
+
155
+ /*when(id){
156
+
157
+ R.id.gu -> myHandImage.setImageResource(R.drawable.gu)
158
+
159
+ R.id.choki -> myHandImage.setImageResource(R.drawable.choki)
160
+
161
+ R.id.pa -> myHandImage.setImageResource(R.drawable.pa)
162
+
163
+ }
164
+
165
+ */
166
+
167
+ //勝敗を判定
168
+
35
- val gameResult={comhand-myHand+3}%3
169
+ val gameResult=(comhand-myHand+3)%3
36
170
 
37
171
  when(gameResult)
38
172
 
39
173
  {
40
174
 
41
- 0->resultLabel.setText(R.string.result_draw)//引き分け
175
+ 0 ->resultLabel.setText(R.string.result_draw)//引き分け
42
-
176
+
43
- 1->resultLabel.setText(R.string.result_win) //勝ち
177
+ 1 ->resultLabel.setText(R.string.result_win) //勝ち
44
-
178
+
45
- 2->resultLabel.setText(R.string.result_lose) //負け
179
+ 2 ->resultLabel.setText(R.string.result_lose) //負け
46
180
 
47
181
 
48
182
 
49
183
  }
50
184
 
185
+ backButton.setOnClickListener{finish()}
186
+
187
+
188
+
189
+
190
+
51
191
  ```
52
192
 
53
193
 

1

文言の修正

2019/11/19 06:49

投稿

reguosu22
reguosu22

スコア9

test CHANGED
@@ -1 +1 @@
1
- kotlinでAndroid Studioのアプリ作成中のエラー
1
+ kotlinでAndroid Studioのエラー"Expecting member declaration"
test CHANGED
@@ -15,8 +15,6 @@
15
15
  Expecting member declaration
16
16
 
17
17
 
18
-
19
- Unexpected tokens (use ';' to separate expressions on the same line)
20
18
 
21
19
  ```
22
20
 
@@ -56,6 +54,10 @@
56
54
 
57
55
  ### 試したこと
58
56
 
57
+ 調べてみましたが、いまいちよくわかりません。
58
+
59
+ よろしくお願いいたします。
60
+
59
61
 
60
62
 
61
63
  ここに問題に対して試したことを記載してください。