質問編集履歴

3

コードの追加

2019/01/08 05:26

投稿

Rosetta0703
Rosetta0703

スコア8

test CHANGED
File without changes
test CHANGED
@@ -14,67 +14,269 @@
14
14
 
15
15
 
16
16
 
17
+ ```MainActivity.java
18
+
19
+ java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.st〇〇〇.mailer2/com.example.st〇〇〇.mailer2.SubActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
20
+
21
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
22
+
23
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
24
+
25
+ at android.app.ActivityThread.-wrap11(Unknown Source:0)
26
+
27
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
28
+
29
+ at android.os.Handler.dispatchMessage(Handler.java:105)
30
+
31
+ at android.os.Looper.loop(Looper.java:251)
32
+
33
+ at android.app.ActivityThread.main(ActivityThread.java:6572)
34
+
35
+ at java.lang.reflect.Method.invoke(Native Method)
36
+
37
+ at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
38
+
39
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
40
+
41
+ Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
42
+
43
+ at com.example.st081551.mailler2.SubActivity.onCreate(SubActivity.java:40)
44
+
45
+ at android.app.Activity.performCreate(Activity.java:6975)
46
+
47
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
48
+
49
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
50
+
51
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) 
52
+
53
+ at android.app.ActivityThread.-wrap11(Unknown Source:0) 
54
+
55
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) 
56
+
57
+ at android.os.Handler.dispatchMessage(Handler.java:105) 
58
+
59
+ at android.os.Looper.loop(Looper.java:251) 
60
+
61
+ at android.app.ActivityThread.main(ActivityThread.java:6572) 
62
+
63
+ at java.lang.reflect.Method.invoke(Native Method) 
64
+
65
+ at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
66
+
67
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
68
+
17
69
  ```
18
70
 
19
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.st〇〇〇.mailer2/com.example.st〇〇〇.mailer2.SubActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
20
-
21
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
22
-
23
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
24
-
25
- at android.app.ActivityThread.-wrap11(Unknown Source:0)
26
-
27
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
28
-
29
- at android.os.Handler.dispatchMessage(Handler.java:105)
30
-
31
- at android.os.Looper.loop(Looper.java:251)
32
-
33
- at android.app.ActivityThread.main(ActivityThread.java:6572)
34
-
35
- at java.lang.reflect.Method.invoke(Native Method)
36
-
37
- at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
38
-
39
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
40
-
41
- Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
42
-
43
- at com.example.st081551.mailler2.SubActivity.onCreate(SubActivity.java:40)
44
-
45
- at android.app.Activity.performCreate(Activity.java:6975)
46
-
47
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
48
-
49
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
50
-
51
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) 
52
-
53
- at android.app.ActivityThread.-wrap11(Unknown Source:0) 
54
-
55
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) 
56
-
57
- at android.os.Handler.dispatchMessage(Handler.java:105) 
58
-
59
- at android.os.Looper.loop(Looper.java:251) 
60
-
61
- at android.app.ActivityThread.main(ActivityThread.java:6572) 
62
-
63
- at java.lang.reflect.Method.invoke(Native Method) 
64
-
65
- at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
66
-
67
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
71
+
72
+
73
+ ### 該当のソースコード
74
+
75
+
76
+
77
+ ```MainActivity.java
78
+
79
+ package com.example.st〇〇〇.mailer2;
80
+
81
+
82
+
83
+ import android.content.Intent;
84
+
85
+ import android.os.Bundle;
86
+
87
+ import android.support.v7.app.AppCompatActivity;
88
+
89
+ import android.view.View;
90
+
91
+ import android.widget.Button;
92
+
93
+ import android.net.Uri;
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ public class MainActivity extends AppCompatActivity {
104
+
105
+
106
+
107
+ @Override
108
+
109
+ protected void onCreate(Bundle savedInstanceState) {
110
+
111
+ super.onCreate(savedInstanceState);
112
+
113
+ setContentView(R.layout.activity_main);
114
+
115
+
116
+
117
+ Button button = findViewById(R.id.button);
118
+
119
+ button.setOnClickListener(new View.OnClickListener() {
120
+
121
+ @Override
122
+
123
+ public void onClick(View v) {
124
+
125
+ // mailer 呼び出し
126
+
127
+ syukatuMailer();
128
+
129
+ }
130
+
131
+ });
132
+
133
+
134
+
135
+ Button button2 = findViewById(R.id.button2);
136
+
137
+ button2.setOnClickListener(new View.OnClickListener() {
138
+
139
+ @Override
140
+
141
+ public void onClick(View v) {
142
+
143
+ // mailer 呼び出し
144
+
145
+ callMailer();
146
+
147
+ }
148
+
149
+ });
150
+
151
+
152
+
153
+ Button button3 = findViewById(R.id.button3);
154
+
155
+ button3.setOnClickListener(new View.OnClickListener() {
156
+
157
+ @Override
158
+
159
+ public void onClick(View v) {
160
+
161
+ Intent intent = new Intent(getApplication(), SubActivity.class);
162
+
163
+ startActivity(intent);
164
+
165
+ }
166
+
167
+ });
168
+
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+ String sep = System.getProperty("line.separator");
178
+
179
+
180
+
181
+
182
+
183
+ private void syukatuMailer(){
184
+
185
+ Intent intent = new Intent();
186
+
187
+ intent.setAction(Intent.ACTION_SENDTO);
188
+
189
+
190
+
191
+ Intent st_intent = getIntent();
192
+
193
+ String st_number = st_intent.getStringExtra("aaa");
194
+
195
+ String st_name = st_intent.getStringExtra("bbb");
196
+
197
+
198
+
199
+ intent.setType("text/plain");
200
+
201
+ intent.setData(Uri.parse("mailto:xxx@yyy.zzz"));
202
+
203
+ intent.putExtra(Intent.EXTRA_SUBJECT, "タイトル");
204
+
205
+ intent.putExtra(Intent.EXTRA_TEXT, "就活の連絡です。"
206
+
207
+ +sep
208
+
209
+ + st_number
210
+
211
+ +sep
212
+
213
+ + st_name );
214
+
215
+
216
+
217
+ // startActivity(intent);
218
+
219
+ startActivity(Intent.createChooser(intent, null));
220
+
221
+
222
+
223
+ }
224
+
225
+
226
+
227
+ private void callMailer(){
228
+
229
+ Intent intent = new Intent();
230
+
231
+ intent.setAction(Intent.ACTION_SENDTO);
232
+
233
+
234
+
235
+ Intent st_intent = getIntent();
236
+
237
+ String st_number = st_intent.getStringExtra("aaa");
238
+
239
+ String st_name = st_intent.getStringExtra("bbb");
240
+
241
+
242
+
243
+ intent.setType("text/plain");
244
+
245
+ intent.setData(Uri.parse("mailto:xxx@yyy.zzz"));
246
+
247
+ intent.putExtra(Intent.EXTRA_SUBJECT, "タイトル");
248
+
249
+ intent.putExtra(Intent.EXTRA_TEXT, "法事の連絡です。\r\n" +
250
+
251
+ "〇〇大学" +
252
+
253
+ ""
254
+
255
+ +sep
256
+
257
+ + st_number
258
+
259
+ +sep
260
+
261
+ +st_name );
262
+
263
+
264
+
265
+ // startActivity(intent);
266
+
267
+ startActivity(Intent.createChooser(intent, null));
268
+
269
+
270
+
271
+ }
272
+
273
+ }
68
274
 
69
275
  ```
70
276
 
71
277
 
72
278
 
73
- ### 該当のソースコード
74
-
75
-
76
-
77
- ```MainActivity.java
279
+ ```SubActivity.java
78
280
 
79
281
  package com.example.st〇〇〇.mailer2;
80
282
 
@@ -90,81 +292,125 @@
90
292
 
91
293
  import android.widget.Button;
92
294
 
295
+ import android.widget.EditText;
296
+
297
+ import android.widget.TextView;
298
+
93
- import android.net.Uri;
299
+ import android.widget.Spinner;
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
103
- public class MainActivity extends AppCompatActivity {
313
+ public class SubActivity extends AppCompatActivity {
314
+
315
+
316
+
317
+
318
+
319
+ EditText editText,editText2;
320
+
321
+ Button okButton;
322
+
323
+
104
324
 
105
325
 
106
326
 
107
327
  @Override
108
328
 
109
- protected void onCreate(Bundle savedInstanceState) {
329
+ public void onCreate(Bundle savedInstanceState) {
110
330
 
111
331
  super.onCreate(savedInstanceState);
112
332
 
113
- setContentView(R.layout.activity_main);
333
+ setContentView(R.layout.activity_sub);
334
+
335
+
336
+
114
-
337
+ editText = findViewById(R.id.edit_st_number);
338
+
115
-
339
+ editText2 = findViewById(R.id.edit_st_name);
340
+
116
-
341
+ final Spinner school = (Spinner)this.findViewById(R.id.school_spinner);
342
+
343
+
344
+
345
+
346
+
347
+
348
+
117
- Button button = findViewById(R.id.button);
349
+ okButton = (Button) findViewById(R.id.button3);
118
-
350
+
119
- button.setOnClickListener(new View.OnClickListener() {
351
+ okButton.setOnClickListener(new View.OnClickListener() {
352
+
353
+ public void onClick(View v) {
354
+
355
+
356
+
357
+
358
+
359
+ String st_number = editText.getText().toString();
360
+
361
+ String st_name = editText2.getText().toString();
362
+
363
+ String str_school = (String)school.getSelectedItem();
364
+
365
+
366
+
367
+ Intent st_intent = new Intent(getApplication(),MainActivity.class);
368
+
369
+ st_intent.putExtra("aaa",st_number);
370
+
371
+ st_intent.putExtra("bbb",st_name);
372
+
373
+ st_intent.putExtra("ccc",st_school);
374
+
375
+ startActivity(st_intent);
376
+
377
+ }
378
+
379
+ });
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+ /*
390
+
391
+ Button returnButton = findViewById(R.id.return_button);
392
+
393
+ returnButton.setOnClickListener(new View.OnClickListener() {
120
394
 
121
395
  @Override
122
396
 
123
397
  public void onClick(View v) {
124
398
 
399
+ Intent intent2 =new Intent(getApplication(),MainActivity.class);
400
+
125
- // mailer 呼び出し
401
+ intent2.putExtra("aaa",st_text);
126
-
402
+
127
- syukatuMailer();
403
+ startActivity(intent2);
128
404
 
129
405
  }
130
406
 
131
407
  });
132
408
 
133
-
134
-
135
- Button button2 = findViewById(R.id.button2);
136
-
137
- button2.setOnClickListener(new View.OnClickListener() {
138
-
139
- @Override
409
+ */
140
-
141
- public void onClick(View v) {
410
+
142
-
143
- // mailer 呼び出し
411
+
144
-
145
- callMailer();
412
+
146
-
147
- }
413
+
148
-
149
- });
150
-
151
-
152
-
153
- Button button3 = findViewById(R.id.button3);
154
-
155
- button3.setOnClickListener(new View.OnClickListener() {
156
-
157
- @Override
158
-
159
- public void onClick(View v) {
160
-
161
- Intent intent = new Intent(getApplication(), SubActivity.class);
162
-
163
- startActivity(intent);
164
-
165
- }
166
-
167
- });
168
414
 
169
415
  }
170
416
 
@@ -172,106 +418,12 @@
172
418
 
173
419
 
174
420
 
175
-
176
-
177
- String sep = System.getProperty("line.separator");
178
-
179
-
180
-
181
-
182
-
183
- private void syukatuMailer(){
184
-
185
- Intent intent = new Intent();
186
-
187
- intent.setAction(Intent.ACTION_SENDTO);
188
-
189
-
190
-
191
- Intent st_intent = getIntent();
192
-
193
- String st_number = st_intent.getStringExtra("aaa");
194
-
195
- String st_name = st_intent.getStringExtra("bbb");
196
-
197
-
198
-
199
- intent.setType("text/plain");
200
-
201
- intent.setData(Uri.parse("mailto:xxx@yyy.zzz"));
202
-
203
- intent.putExtra(Intent.EXTRA_SUBJECT, "タイトル");
204
-
205
- intent.putExtra(Intent.EXTRA_TEXT, "就活の連絡です。"
206
-
207
- +sep
208
-
209
- + st_number
210
-
211
- +sep
212
-
213
- + st_name );
214
-
215
-
216
-
217
- // startActivity(intent);
218
-
219
- startActivity(Intent.createChooser(intent, null));
220
-
221
-
222
-
223
- }
224
-
225
-
226
-
227
- private void callMailer(){
228
-
229
- Intent intent = new Intent();
230
-
231
- intent.setAction(Intent.ACTION_SENDTO);
232
-
233
-
234
-
235
- Intent st_intent = getIntent();
236
-
237
- String st_number = st_intent.getStringExtra("aaa");
238
-
239
- String st_name = st_intent.getStringExtra("bbb");
240
-
241
-
242
-
243
- intent.setType("text/plain");
244
-
245
- intent.setData(Uri.parse("mailto:xxx@yyy.zzz"));
246
-
247
- intent.putExtra(Intent.EXTRA_SUBJECT, "タイトル");
248
-
249
- intent.putExtra(Intent.EXTRA_TEXT, "法事の連絡です。\r\n" +
250
-
251
- "〇〇大学" +
252
-
253
- ""
254
-
255
- +sep
256
-
257
- + st_number
258
-
259
- +sep
260
-
261
- +st_name );
262
-
263
-
264
-
265
- // startActivity(intent);
266
-
267
- startActivity(Intent.createChooser(intent, null));
268
-
269
-
270
-
271
- }
272
-
273
421
  }
274
422
 
423
+
424
+
425
+
426
+
275
427
  ```
276
428
 
277
429
 

2

追記

2019/01/08 05:25

投稿

Rosetta0703
Rosetta0703

スコア8

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
 
10
10
 
11
+
12
+
11
13
  ### エラーメッセージ(Logcat部分)
12
14
 
13
15
 
@@ -282,8 +284,12 @@
282
284
 
283
285
 
284
286
 
285
- ### 補足情報(FW/ツールのバージョンなど)
287
+ ### 補足情報
288
+
289
+
290
+
286
-
291
+ button3のIntent処理で怒られているのはなんとなく分かるのですが、元々このコードでエラーも出ず動いていたので何が原因か分かっていない状態です。
292
+
287
-
293
+ 元はRに赤線が出まくってビルドが出来なくなったので、いろいろ試したらビルドはできるのものの遷移する際にクラッシュするという状態です。
288
-
294
+
289
- ここにり詳細な情報を記載ださい。
295
+ ご教授しくお願します

1

誤字

2019/01/07 08:17

投稿

Rosetta0703
Rosetta0703

スコア8

test CHANGED
@@ -1 +1 @@
1
- Intentを使った画面遷移
1
+ Intentを使った画面遷移がクラッシュしてしまう
test CHANGED
File without changes