質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -111,3 +111,91 @@
|
|
111
111
|
checkBox2がcheckされてbuttonを押したときに変数をmainactivityに持ってくるというプログラムを書いているのですが、buttonを押すと落ちてしまいます。
|
112
112
|
|
113
113
|
どう直せばよいのでしょうか?
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
```ここに言語を入力
|
118
|
+
|
119
|
+
import android.app.Application;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
public class MyApp extends Application {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
private String testString = "default";
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
@Override
|
132
|
+
|
133
|
+
public void onCreate() {
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
public String getTestString() {
|
142
|
+
|
143
|
+
return testString;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
public void setTestString(String str) {
|
148
|
+
|
149
|
+
testString = str;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```ここに言語を入力
|
160
|
+
|
161
|
+
import android.os.Bundle;
|
162
|
+
|
163
|
+
import android.support.v7.app.AppCompatActivity;
|
164
|
+
|
165
|
+
import android.widget.TextView;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public class mainactivity extends AppCompatActivity {
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
@Override
|
174
|
+
|
175
|
+
protected void onCreate(Bundle savedInstanceState) {
|
176
|
+
|
177
|
+
super.onCreate(savedInstanceState);
|
178
|
+
|
179
|
+
setContentView(R.layout.activity_sub);
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
MyApp myApp = (MyApp) this.getApplication();
|
184
|
+
|
185
|
+
String str = myApp.getTestString();
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
TextView TextView2 = (TextView)findViewById(R.id.TextView2);
|
190
|
+
|
191
|
+
TextView2.setText(str);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
```
|