質問編集履歴

9

内容の変更

2020/09/30 13:28

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- BottomNavigationViewに最初に表示される予定のFragmentはfirstFragmentです。
9
+ BottomNavigationViewに最初に表示される予定のFragmentはfirstFragment.javaです。
10
10
 
11
11
  画面には一応ナビゲーションバーはきちんと表示されています。
12
12
 

8

内容の変更

2020/09/30 13:28

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、2か所でエラーが発生します。
4
4
 
5
- エラーに個所を削除してエミュレータを起動しようとすると、アプリが落ちます。
5
+ エラーの箇所を削除してエミュレータを起動しようとすると、アプリが落ちます。
6
6
 
7
7
 
8
8
 

7

内容の変更

2020/09/30 13:21

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -180,110 +180,72 @@
180
180
 
181
181
 
182
182
 
183
- ```errormsg
184
-
185
- 32522-32522/com.example.eiyoukun E/AndroidRuntime: FATAL EXCEPTION: main
186
-
187
- Process: com.example.eiyoukun, PID: 32522
188
-
189
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
190
-
191
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
192
-
193
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
194
-
195
- at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
196
-
197
- at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
198
-
199
- at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
200
-
201
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
202
-
203
- at android.os.Handler.dispatchMessage(Handler.java:107)
204
-
205
- at android.os.Looper.loop(Looper.java:213)
206
-
207
- at android.app.ActivityThread.main(ActivityThread.java:8147)
208
-
209
- at java.lang.reflect.Method.invoke(Native Method)
210
-
211
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
212
-
213
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
214
-
215
- Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
216
-
217
- Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
218
-
219
- Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment
220
-
221
- at android.app.Fragment.instantiate(Fragment.java:543)
222
-
223
- at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
224
-
225
- at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3569)
226
-
227
- at android.app.FragmentController.onCreateView(FragmentController.java:104)
228
-
229
- at android.app.Activity.onCreateView(Activity.java:7202)
230
-
231
- at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1079)
232
-
233
- at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1007)
234
-
235
- at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
236
-
237
- at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
238
-
239
- at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1094)
240
-
241
- at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
242
-
243
- at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
244
-
245
- at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
246
-
247
- at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:520)
248
-
249
- at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:328)
250
-
251
- at android.app.Activity.setContentView(Activity.java:3439)
252
-
253
- at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:70)
254
-
255
- at android.app.Activity.performCreate(Activity.java:8066)
256
-
257
- at android.app.Activity.performCreate(Activity.java:8054)
258
-
259
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
260
-
261
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
262
-
263
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
264
-
265
- at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
266
-
267
- at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
268
-
269
- at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
270
-
271
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
272
-
273
- at android.os.Handler.dispatchMessage(Handler.java:107)
274
-
275
- at android.os.Looper.loop(Looper.java:213)
276
-
277
- at android.app.ActivityThread.main(ActivityThread.java:8147)
278
-
279
- at java.lang.reflect.Method.invoke(Native Method)
280
-
281
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
282
-
283
- 2020-09-30 21:15:22.438 32522-32522/com.example.eiyoukun E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
284
-
285
- Caused by: java.lang.ClassCastException
286
-
287
- ... 32 more
288
-
289
- ```
183
+ ```mynavxml
184
+
185
+ <fragment
186
+
187
+ android:id="@+id/fragment1"
188
+
189
+ android:name="com.example.test.Fragment1"
190
+
191
+ android:label="fragment_1"
192
+
193
+ tools:layout="@layout/fragment_1" />
194
+
195
+ <fragment
196
+
197
+ android:id="@+id/fragment2"
198
+
199
+ android:name="com.example.test.Fragment2"
200
+
201
+ android:label="fragment_2"
202
+
203
+ tools:layout="@layout/fragment_2" />
204
+
205
+ <fragment
206
+
207
+ android:id="@+id/fragment3"
208
+
209
+ android:name="com.example.test.Fragment3"
210
+
211
+ android:label="fragment_3"
212
+
213
+ tools:layout="@layout/fragment_3" />
214
+
215
+ ```
216
+
217
+
218
+
219
+ ```bottommenuxml
220
+
221
+ <fragment
222
+
223
+ android:id="@+id/fragment1"
224
+
225
+ android:name="com.example.test.Fragment1"
226
+
227
+ android:label="fragment_1"
228
+
229
+ tools:layout="@layout/fragment_1" />
230
+
231
+ <fragment
232
+
233
+ android:id="@+id/fragment2"
234
+
235
+ android:name="com.example.test.Fragment2"
236
+
237
+ android:label="fragment_2"
238
+
239
+ tools:layout="@layout/fragment_2" />
240
+
241
+ <fragment
242
+
243
+ android:id="@+id/fragment3"
244
+
245
+ android:name="com.example.test.Fragment3"
246
+
247
+ android:label="fragment_3"
248
+
249
+ tools:layout="@layout/fragment_3" />
250
+
251
+ ```

6

内容の変更

2020/09/30 13:19

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -180,176 +180,110 @@
180
180
 
181
181
 
182
182
 
183
- ```fragmentfirstxml
184
-
185
- <?xml version="1.0" encoding="utf-8"?>
186
-
187
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
-
189
- xmlns:app="http://schemas.android.com/apk/res-auto"
190
-
191
- xmlns:tools="http://schemas.android.com/tools"
192
-
193
- android:layout_width="match_parent"
194
-
195
- android:layout_height="match_parent"
196
-
197
- tools:context=".firstFragment">
198
-
199
-
200
-
201
- <!-- TODO: Update blank fragment layout -->
202
-
203
- <TextView
204
-
205
- android:layout_width="216dp"
206
-
207
- android:layout_height="167dp"
208
-
209
- android:text="first_fragment"
210
-
211
- app:layout_constraintBottom_toBottomOf="parent"
212
-
213
- app:layout_constraintEnd_toEndOf="parent"
214
-
215
- app:layout_constraintStart_toStartOf="parent"
216
-
217
- app:layout_constraintTop_toTopOf="parent" />
218
-
219
-
220
-
221
- </androidx.constraintlayout.widget.ConstraintLayout>
183
+ ```errormsg
184
+
185
+ 32522-32522/com.example.eiyoukun E/AndroidRuntime: FATAL EXCEPTION: main
186
+
187
+ Process: com.example.eiyoukun, PID: 32522
188
+
189
+ java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
190
+
191
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
192
+
193
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
194
+
195
+ at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
196
+
197
+ at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
198
+
199
+ at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
200
+
201
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
202
+
203
+ at android.os.Handler.dispatchMessage(Handler.java:107)
204
+
205
+ at android.os.Looper.loop(Looper.java:213)
206
+
207
+ at android.app.ActivityThread.main(ActivityThread.java:8147)
208
+
209
+ at java.lang.reflect.Method.invoke(Native Method)
210
+
211
+ at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
212
+
213
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
214
+
215
+ Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
216
+
217
+ Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
218
+
219
+ Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment
220
+
221
+ at android.app.Fragment.instantiate(Fragment.java:543)
222
+
223
+ at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
224
+
225
+ at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3569)
226
+
227
+ at android.app.FragmentController.onCreateView(FragmentController.java:104)
228
+
229
+ at android.app.Activity.onCreateView(Activity.java:7202)
230
+
231
+ at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1079)
232
+
233
+ at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1007)
234
+
235
+ at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
236
+
237
+ at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
238
+
239
+ at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1094)
240
+
241
+ at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
242
+
243
+ at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
244
+
245
+ at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
246
+
247
+ at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:520)
248
+
249
+ at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:328)
250
+
251
+ at android.app.Activity.setContentView(Activity.java:3439)
252
+
253
+ at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:70)
254
+
255
+ at android.app.Activity.performCreate(Activity.java:8066)
256
+
257
+ at android.app.Activity.performCreate(Activity.java:8054)
258
+
259
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
260
+
261
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
262
+
263
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
264
+
265
+ at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
266
+
267
+ at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
268
+
269
+ at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
270
+
271
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
272
+
273
+ at android.os.Handler.dispatchMessage(Handler.java:107)
274
+
275
+ at android.os.Looper.loop(Looper.java:213)
276
+
277
+ at android.app.ActivityThread.main(ActivityThread.java:8147)
278
+
279
+ at java.lang.reflect.Method.invoke(Native Method)
280
+
281
+ at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
282
+
283
+ 2020-09-30 21:15:22.438 32522-32522/com.example.eiyoukun E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
284
+
285
+ Caused by: java.lang.ClassCastException
286
+
287
+ ... 32 more
222
288
 
223
289
  ```
224
-
225
- ```firstfragmentjava
226
-
227
- package com.example.eiyoukun;
228
-
229
-
230
-
231
- import android.os.Bundle;
232
-
233
-
234
-
235
- import androidx.fragment.app.Fragment;
236
-
237
-
238
-
239
- import android.view.LayoutInflater;
240
-
241
- import android.view.View;
242
-
243
- import android.view.ViewGroup;
244
-
245
-
246
-
247
- /**
248
-
249
- * A simple {@link Fragment} subclass.
250
-
251
- * Use the {@link firstFragment#newInstance} factory method to
252
-
253
- * create an instance of this fragment.
254
-
255
- */
256
-
257
- public class firstFragment extends Fragment {
258
-
259
-
260
-
261
- // TODO: Rename parameter arguments, choose names that match
262
-
263
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
264
-
265
- private static final String ARG_PARAM1 = "param1";
266
-
267
- private static final String ARG_PARAM2 = "param2";
268
-
269
-
270
-
271
- // TODO: Rename and change types of parameters
272
-
273
- private String mParam1;
274
-
275
- private String mParam2;
276
-
277
-
278
-
279
- public firstFragment() {
280
-
281
- // Required empty public constructor
282
-
283
- }
284
-
285
-
286
-
287
- /**
288
-
289
- * Use this factory method to create a new instance of
290
-
291
- * this fragment using the provided parameters.
292
-
293
- *
294
-
295
- * @param param1 Parameter 1.
296
-
297
- * @param param2 Parameter 2.
298
-
299
- * @return A new instance of fragment firstFragment.
300
-
301
- */
302
-
303
- // TODO: Rename and change types and number of parameters
304
-
305
- public static firstFragment newInstance(String param1, String param2) {
306
-
307
- firstFragment fragment = new firstFragment();
308
-
309
- Bundle args = new Bundle();
310
-
311
- args.putString(ARG_PARAM1, param1);
312
-
313
- args.putString(ARG_PARAM2, param2);
314
-
315
- fragment.setArguments(args);
316
-
317
- return fragment;
318
-
319
- }
320
-
321
-
322
-
323
- @Override
324
-
325
- public void onCreate(Bundle savedInstanceState) {
326
-
327
- super.onCreate(savedInstanceState);
328
-
329
- if (getArguments() != null) {
330
-
331
- mParam1 = getArguments().getString(ARG_PARAM1);
332
-
333
- mParam2 = getArguments().getString(ARG_PARAM2);
334
-
335
- }
336
-
337
- }
338
-
339
-
340
-
341
- @Override
342
-
343
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
344
-
345
- Bundle savedInstanceState) {
346
-
347
- // Inflate the layout for this fragment
348
-
349
- return inflater.inflate(R.layout.fragment_first, container, false);
350
-
351
- }
352
-
353
-
354
-
355
- ```

5

内容の変更

2020/09/30 12:28

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
 
17
- 作成したFragment.javaと、対するmy_navi.xmlは
17
+ 作成したFragment.javaと、対するmy_navi.xmlのID
18
18
 
19
19
  ・firstFragment.java・・・・fragmentfirst3
20
20
 

4

内容の変更

2020/09/30 10:37

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- MainActivityから最初に遷移する予定のFragmentはfirstFragmentです。
9
+ BottomNavigationViewに最初に表示される予定のFragmentはfirstFragmentです。
10
10
 
11
11
  画面には一応ナビゲーションバーはきちんと表示されています。
12
12
 

3

内容の変更

2020/09/29 10:37

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -1,20 +1,26 @@
1
1
  ## 分からないこと
2
2
 
3
- MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、エミュレタを起動ようとするとアプリが落ちます。
3
+ MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、2か所でが発生します。
4
+
4
-
5
+ エラーに個所を削除してエミュレータを起動しようとすると、アプリが落ちます。
6
+
7
+
8
+
5
-
9
+ MainActivityから最初に遷移する予定のFragmentはfirstFragmentです。
6
10
 
7
11
  画面には一応ナビゲーションバーはきちんと表示されています。
8
12
 
9
13
 
10
14
 
15
+
16
+
11
- 作成したFragmentは
17
+ 作成したFragment.javaと、対するmy_navi.xml
12
-
18
+
13
- ・firstFragment.java・・・・fragmentfirst3.xml
19
+ ・firstFragment.java・・・・fragmentfirst3
14
-
20
+
15
- ・secondFragment.java・・・・fragmentsecond2.xml
21
+ ・secondFragment.java・・・・fragmentsecond2
16
-
22
+
17
- ・thirdFragment.java・・・・fragmentthird.xml
23
+ ・thirdFragment.java・・・・fragmentthird
18
24
 
19
25
  です。
20
26
 
@@ -22,135 +28,185 @@
22
28
 
23
29
  ## コード
24
30
 
25
- ```errormessage
26
-
27
- E/AndroidRuntime: FATAL EXCEPTION: main
28
-
29
- Process: com.example.eiyoukun, PID:
30
-
31
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
32
-
33
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
34
-
35
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
36
-
37
- at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
38
-
39
- at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
40
-
41
- at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
42
-
43
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
44
-
45
- at android.os.Handler.dispatchMessage(Handler.java:107)
46
-
47
- at android.os.Looper.loop(Looper.java:213)
48
-
49
- at android.app.ActivityThread.main(ActivityThread.java:8147)
50
-
51
- at java.lang.reflect.Method.invoke(Native Method)
52
-
53
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
54
-
55
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
56
-
57
- Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
58
-
59
- Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
60
-
61
- Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment
62
-
63
- at android.app.Fragment.instantiate(Fragment.java:543)
64
-
65
- at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
66
-
67
- at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3569)
68
-
69
- at android.app.FragmentController.onCreateView(FragmentController.java:104)
70
-
71
- at android.app.Activity.onCreateView(Activity.java:7202)
72
-
73
- at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1079)
74
-
75
- at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1007)
76
-
77
- at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
78
-
79
- at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
80
-
81
- at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1094)
82
-
83
- at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
84
-
85
- at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
86
-
87
- at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
88
-
89
- at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:520)
90
-
91
- at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:328)
92
-
93
- at android.app.Activity.setContentView(Activity.java:3439)
94
-
95
- at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:71)
96
-
97
- at android.app.Activity.performCreate(Activity.java:8066)
98
-
99
- at android.app.Activity.performCreate(Activity.java:8054)
100
-
101
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
102
-
103
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
104
-
105
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
106
-
107
- at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
108
-
109
- at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
110
-
111
- at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
112
-
113
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
114
-
115
- at android.os.Handler.dispatchMessage(Handler.java:107)
116
-
117
- at android.os.Looper.loop(Looper.java:213)
118
-
119
- at android.app.ActivityThread.main(ActivityThread.java:8147)
120
-
121
- at java.lang.reflect.Method.invoke(Native Method)
122
-
123
- at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
124
-
125
- E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
126
-
127
- Caused by: java.lang.ClassCastException
128
-
129
- ... 32 more
31
+
32
+
33
+
34
+
35
+
36
+
37
+ ```activitymainxml
38
+
39
+
40
+
41
+ <中略>
42
+
43
+
44
+
45
+ <com.google.android.material.bottomnavigation.BottomNavigationView
46
+
47
+ android:id="@+id/bottomNavigationView"
48
+
49
+ android:background="#fff"
50
+
51
+ android:layout_width="411dp"
52
+
53
+ android:layout_height="48dp"
54
+
55
+ app:layout_constraintBottom_toBottomOf="parent"
56
+
57
+ app:layout_constraintEnd_toEndOf="parent"
58
+
59
+ app:layout_constraintStart_toStartOf="parent"
60
+
61
+ app:menu="@menu/bottom_menu"
62
+
63
+ />
64
+
65
+
66
+
67
+ <fragment
68
+
69
+ android:id="@+id/fragment2"
70
+
71
+ android:name="androidx.navigation.fragment.NavHostFragment"
72
+
73
+ android:layout_width="416dp"
74
+
75
+ android:layout_height="45dp"
76
+
77
+ app:defaultNavHost="true"
78
+
79
+ app:layout_constraintBottom_toBottomOf="parent"
80
+
81
+ app:layout_constraintEnd_toEndOf="parent"
82
+
83
+ app:layout_constraintStart_toStartOf="parent"
84
+
85
+ app:navGraph="@navigation/my_nav" />
86
+
87
+
130
88
 
131
89
  ```
132
90
 
133
91
 
134
92
 
135
-
136
-
137
- ```activitymainxml
93
+ ```mainactivityjava
94
+
138
-
95
+ import androidx.fragment.app.Fragment;
96
+
139
-
97
+ import com.google.android.material.bottomnavigation.BottomNavigationView;
98
+
99
+
100
+
140
-
101
+ public class MainActivity extends Activity {
102
+
103
+
104
+
105
+ private BottomNavigationView.OnNavigationItemSelectedListener navListener =
106
+
107
+ new BottomNavigationView.OnNavigationItemSelectedListener() {
108
+
109
+ @Override
110
+
111
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
112
+
113
+ Fragment selectedFragment = null;
114
+
115
+
116
+
117
+ switch (item.getItemId()){
118
+
119
+ case R.id.firstFragment3:
120
+
121
+ selectedFragment = new firstFragment();  //new firstFragmentに赤線が引かれるがmsgなし
122
+
123
+ break;
124
+
125
+ case R.id.secondFragment2:
126
+
127
+ selectedFragment = new secondFragment();
128
+
129
+ break;
130
+
131
+ case R.id.thirdFragment:
132
+
133
+ selectedFragment = new thirdFragment();
134
+
135
+ break;
136
+
137
+ }
138
+
139
+ //selectedFragmentに赤線 msgなし
140
+
141
+ getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,selectedFragment).commit(); 
142
+
143
+
144
+
145
+ return true;
146
+
147
+ }
148
+
149
+ };
150
+
151
+
152
+
153
+ @Override
154
+
155
+ protected void onCreate(Bundle savedInstanceState) {
156
+
157
+
158
+
141
- <中略>
159
+ <中略>
142
-
143
-
144
-
160
+
161
+
162
+
145
- <com.google.android.material.bottomnavigation.BottomNavigationView
163
+ BottomNavigationView bottomNav = findViewById(R.id.bottomNavigationView);
164
+
146
-
165
+ bottomNav.setOnNavigationItemReselectedListener((BottomNavigationView.OnNavigationItemReselectedListener) navListener);
166
+
167
+ getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,firstFragment()).commit();
168
+
169
+
170
+
171
+ }
172
+
173
+
174
+
175
+ }
176
+
177
+
178
+
179
+ ```
180
+
181
+
182
+
183
+ ```fragmentfirstxml
184
+
185
+ <?xml version="1.0" encoding="utf-8"?>
186
+
187
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
+
189
+ xmlns:app="http://schemas.android.com/apk/res-auto"
190
+
147
- android:id="@+id/bottomNavigationView"
191
+ xmlns:tools="http://schemas.android.com/tools"
148
-
192
+
149
- android:background="#fff"
193
+ android:layout_width="match_parent"
194
+
150
-
195
+ android:layout_height="match_parent"
196
+
197
+ tools:context=".firstFragment">
198
+
199
+
200
+
201
+ <!-- TODO: Update blank fragment layout -->
202
+
203
+ <TextView
204
+
151
- android:layout_width="411dp"
205
+ android:layout_width="216dp"
152
-
206
+
153
- android:layout_height="48dp"
207
+ android:layout_height="167dp"
208
+
209
+ android:text="first_fragment"
154
210
 
155
211
  app:layout_constraintBottom_toBottomOf="parent"
156
212
 
@@ -158,121 +214,141 @@
158
214
 
159
215
  app:layout_constraintStart_toStartOf="parent"
160
216
 
161
- app:menu="@menu/bottom_menu"
162
-
163
- />
164
-
165
-
166
-
167
- <fragment
168
-
169
- android:id="@+id/fragment2"
170
-
171
- android:name="androidx.navigation.fragment.NavHostFragment"
172
-
173
- android:layout_width="416dp"
174
-
175
- android:layout_height="45dp"
176
-
177
- app:defaultNavHost="true"
178
-
179
- app:layout_constraintBottom_toBottomOf="parent"
180
-
181
- app:layout_constraintEnd_toEndOf="parent"
217
+ app:layout_constraintTop_toTopOf="parent" />
182
-
218
+
219
+
220
+
183
- app:layout_constraintStart_toStartOf="parent"
221
+ </androidx.constraintlayout.widget.ConstraintLayout>
184
-
185
- app:navGraph="@navigation/my_nav" />
186
-
187
-
188
222
 
189
223
  ```
190
224
 
191
-
192
-
193
- ```mainactivityjava
225
+ ```firstfragmentjava
226
+
227
+ package com.example.eiyoukun;
228
+
229
+
230
+
231
+ import android.os.Bundle;
232
+
233
+
194
234
 
195
235
  import androidx.fragment.app.Fragment;
196
236
 
197
- import com.google.android.material.bottomnavigation.BottomNavigationView;
198
-
199
-
200
-
201
- public class MainActivity extends Activity {
202
-
203
-
204
-
205
- private BottomNavigationView.OnNavigationItemSelectedListener navListener =
206
-
207
- new BottomNavigationView.OnNavigationItemSelectedListener() {
208
-
209
- @Override
210
-
211
- public boolean onNavigationItemSelected(@NonNull MenuItem item) {
212
-
213
- Fragment selectedFragment = null;
214
-
215
-
216
-
217
- switch (item.getItemId()){
218
-
219
- case R.id.firstFragment3:
220
-
221
- selectedFragment = new firstFragment();  //new firstFragmentに赤線が引かれるがmsgなし
222
-
223
- break;
224
-
225
- case R.id.secondFragment2:
226
-
227
- selectedFragment = new secondFragment();
228
-
229
- break;
230
-
231
- case R.id.thirdFragment:
232
-
233
- selectedFragment = new thirdFragment();
234
-
235
- break;
236
-
237
- }
238
-
239
- //selectedFragmentに赤線 msgなし
240
-
241
- getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,selectedFragment).commit(); 
242
-
243
-
244
-
245
- return true;
246
-
247
- }
248
-
249
- };
250
-
251
-
252
-
253
- @Override
254
-
255
- protected void onCreate(Bundle savedInstanceState) {
256
-
257
-
258
-
259
- <中略>
260
-
261
-
262
-
263
- BottomNavigationView bottomNav = findViewById(R.id.bottomNavigationView);
264
-
265
- bottomNav.setOnNavigationItemReselectedListener((BottomNavigationView.OnNavigationItemReselectedListener) navListener);
266
-
267
- getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,firstFragment()).commit();
268
-
269
-
270
-
271
- }
272
-
273
-
274
-
275
- }
237
+
238
+
239
+ import android.view.LayoutInflater;
240
+
241
+ import android.view.View;
242
+
243
+ import android.view.ViewGroup;
244
+
245
+
246
+
247
+ /**
248
+
249
+ * A simple {@link Fragment} subclass.
250
+
251
+ * Use the {@link firstFragment#newInstance} factory method to
252
+
253
+ * create an instance of this fragment.
254
+
255
+ */
256
+
257
+ public class firstFragment extends Fragment {
258
+
259
+
260
+
261
+ // TODO: Rename parameter arguments, choose names that match
262
+
263
+ // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
264
+
265
+ private static final String ARG_PARAM1 = "param1";
266
+
267
+ private static final String ARG_PARAM2 = "param2";
268
+
269
+
270
+
271
+ // TODO: Rename and change types of parameters
272
+
273
+ private String mParam1;
274
+
275
+ private String mParam2;
276
+
277
+
278
+
279
+ public firstFragment() {
280
+
281
+ // Required empty public constructor
282
+
283
+ }
284
+
285
+
286
+
287
+ /**
288
+
289
+ * Use this factory method to create a new instance of
290
+
291
+ * this fragment using the provided parameters.
292
+
293
+ *
294
+
295
+ * @param param1 Parameter 1.
296
+
297
+ * @param param2 Parameter 2.
298
+
299
+ * @return A new instance of fragment firstFragment.
300
+
301
+ */
302
+
303
+ // TODO: Rename and change types and number of parameters
304
+
305
+ public static firstFragment newInstance(String param1, String param2) {
306
+
307
+ firstFragment fragment = new firstFragment();
308
+
309
+ Bundle args = new Bundle();
310
+
311
+ args.putString(ARG_PARAM1, param1);
312
+
313
+ args.putString(ARG_PARAM2, param2);
314
+
315
+ fragment.setArguments(args);
316
+
317
+ return fragment;
318
+
319
+ }
320
+
321
+
322
+
323
+ @Override
324
+
325
+ public void onCreate(Bundle savedInstanceState) {
326
+
327
+ super.onCreate(savedInstanceState);
328
+
329
+ if (getArguments() != null) {
330
+
331
+ mParam1 = getArguments().getString(ARG_PARAM1);
332
+
333
+ mParam2 = getArguments().getString(ARG_PARAM2);
334
+
335
+ }
336
+
337
+ }
338
+
339
+
340
+
341
+ @Override
342
+
343
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
344
+
345
+ Bundle savedInstanceState) {
346
+
347
+ // Inflate the layout for this fragment
348
+
349
+ return inflater.inflate(R.layout.fragment_first, container, false);
350
+
351
+ }
276
352
 
277
353
 
278
354
 

2

内容の変更

2020/09/29 10:35

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -18,11 +18,7 @@
18
18
 
19
19
  です。
20
20
 
21
-
22
-
23
- youtubeの動画を参考にしながら行ったので、何故エラーが出ているのかが分からない状況です。
21
+ ![イメージ説明](5cc6b993b704609a4bf5d26fed5af1c3.png)
24
-
25
-
26
22
 
27
23
  ## コード
28
24
 

1

内容の変更

2020/09/28 17:15

投稿

karin10
karin10

スコア34

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  E/AndroidRuntime: FATAL EXCEPTION: main
32
32
 
33
- Process: com.example.eiyoukun, PID: 21485
33
+ Process: com.example.eiyoukun, PID:
34
34
 
35
35
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
36
36