質問編集履歴

3

HomeFragment.javaのプログラムを追加しました。

2018/08/19 01:05

投稿

Nustin053
Nustin053

スコア12

test CHANGED
File without changes
test CHANGED
@@ -138,115 +138,177 @@
138
138
 
139
139
 
140
140
 
141
+
142
+
141
- ```Java>MainActivity
143
+ ```HomeFragment
142
-
143
-
144
144
 
145
145
  package com.websarver.wings.android.mamaraku;
146
146
 
147
147
 
148
148
 
149
- import android.app.FragmentManager;
149
+ import android.content.Context;
150
+
151
+ import android.net.Uri;
150
152
 
151
153
  import android.os.Bundle;
152
154
 
153
- import android.support.design.widget.FloatingActionButton;
154
-
155
- import android.support.design.widget.Snackbar;
156
-
157
155
  import android.support.v4.app.Fragment;
158
156
 
157
+ import android.view.LayoutInflater;
158
+
159
159
  import android.view.View;
160
160
 
161
- import android.support.design.widget.NavigationView;
162
-
163
- import android.support.v4.view.GravityCompat;
164
-
165
- import android.support.v4.widget.DrawerLayout;
166
-
167
- import android.support.v7.app.ActionBarDrawerToggle;
168
-
169
- import android.support.v7.app.AppCompatActivity;
170
-
171
- import android.support.v7.widget.Toolbar;
172
-
173
- import android.view.Menu;
174
-
175
- import android.view.MenuItem;
176
-
177
-
178
-
179
-
180
-
181
- public class MainActivity extends AppCompatActivity
182
-
183
- implements NavigationView.OnNavigationItemSelectedListener {
184
-
185
-
186
-
187
-
188
-
189
-
161
+ import android.view.ViewGroup;
162
+
163
+
164
+
165
+
166
+
167
+ /**
168
+
169
+ * A simple {@link Fragment} subclass.
170
+
171
+ * Activities that contain this fragment must implement the
172
+
173
+ * {@link HomeFragment.OnFragmentInteractionListener} interface
174
+
175
+ * to handle interaction events.
176
+
177
+ * Use the {@link HomeFragment#newInstance} factory method to
178
+
179
+ * create an instance of this fragment.
180
+
181
+ */
182
+
183
+ public class HomeFragment extends Fragment {
184
+
185
+ // TODO: Rename parameter arguments, choose names that match
186
+
187
+ // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
188
+
189
+ private static final String ARG_PARAM1 = "param1";
190
+
191
+ private static final String ARG_PARAM2 = "param2";
192
+
193
+
194
+
195
+ // TODO: Rename and change types of parameters
196
+
197
+ private String mParam1;
198
+
199
+ private String mParam2;
200
+
201
+
202
+
203
+ private OnFragmentInteractionListener mListener;
204
+
205
+
206
+
207
+ public HomeFragment() {
208
+
209
+ // Required empty public constructor
210
+
211
+ }
212
+
213
+
214
+
215
+ /**
216
+
217
+ * Use this factory method to create a new instance of
218
+
219
+ * this fragment using the provided parameters.
220
+
221
+ *
222
+
223
+ * @param param1 Parameter 1.
224
+
225
+ * @param param2 Parameter 2.
226
+
227
+ * @return A new instance of fragment HomeFragment.
228
+
229
+ */
230
+
231
+ // TODO: Rename and change types and number of parameters
232
+
233
+ public static HomeFragment newInstance(String param1, String param2) {
234
+
235
+ HomeFragment fragment = new HomeFragment();
236
+
237
+ Bundle args = new Bundle();
238
+
239
+ args.putString(ARG_PARAM1, param1);
240
+
241
+ args.putString(ARG_PARAM2, param2);
242
+
243
+ fragment.setArguments(args);
244
+
245
+ return fragment;
246
+
247
+ }
190
248
 
191
249
 
192
250
 
193
251
  @Override
194
252
 
195
- protected void onCreate(Bundle savedInstanceState) {
253
+ public void onCreate(Bundle savedInstanceState) {
196
254
 
197
255
  super.onCreate(savedInstanceState);
198
256
 
199
- setContentView(R.layout.activity_main);
200
-
201
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
202
-
203
- setSupportActionBar(toolbar);
204
-
205
- if (savedInstanceState == null) {
257
+ if (getArguments() != null) {
206
-
258
+
207
- //Fragment load code
259
+ mParam1 = getArguments().getString(ARG_PARAM1);
260
+
261
+ mParam2 = getArguments().getString(ARG_PARAM2);
208
262
 
209
263
  }
210
264
 
211
-
212
-
213
-
214
-
215
-
216
-
217
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
218
-
219
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
220
-
221
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
222
-
223
- drawer.addDrawerListener(toggle);
224
-
225
- toggle.syncState();
226
-
227
-
228
-
229
- NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
230
-
231
- navigationView.setNavigationItemSelectedListener(this);
232
-
233
265
  }
234
266
 
235
267
 
236
268
 
237
269
  @Override
238
270
 
271
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
272
+
273
+ Bundle savedInstanceState) {
274
+
275
+ // Inflate the layout for this fragment
276
+
277
+ return inflater.inflate(R.layout.fragment_home, container, false);
278
+
279
+ }
280
+
281
+
282
+
283
+ // TODO: Rename method, update argument and hook method into UI event
284
+
239
- public void onBackPressed() {
285
+ public void onButtonPressed(Uri uri) {
286
+
240
-
287
+ if (mListener != null) {
288
+
241
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
289
+ mListener.onFragmentInteraction(uri);
290
+
242
-
291
+ }
292
+
293
+ }
294
+
295
+
296
+
297
+ @Override
298
+
299
+ public void onAttach(Context context) {
300
+
301
+ super.onAttach(context);
302
+
243
- if (drawer.isDrawerOpen(GravityCompat.START)) {
303
+ if (context instanceof OnFragmentInteractionListener) {
244
-
304
+
245
- drawer.closeDrawer(GravityCompat.START);
305
+ mListener = (OnFragmentInteractionListener) context;
246
306
 
247
307
  } else {
248
308
 
249
- super.onBackPressed();
309
+ throw new RuntimeException(context.toString()
310
+
311
+ + " must implement OnFragmentInteractionListener");
250
312
 
251
313
  }
252
314
 
@@ -256,130 +318,46 @@
256
318
 
257
319
  @Override
258
320
 
259
- public boolean onCreateOptionsMenu(Menu menu) {
260
-
261
- // Inflate the menu; this adds items to the action bar if it is present.
262
-
263
- getMenuInflater().inflate(R.menu.main, menu);
264
-
265
- return true;
266
-
267
- }
268
-
269
-
270
-
271
- @Override
272
-
273
- public boolean onOptionsItemSelected(MenuItem item) {
274
-
275
- // Handle action bar item clicks here. The action bar will
276
-
277
- // automatically handle clicks on the Home/Up button, so long
278
-
279
- // as you specify a parent activity in AndroidManifest.xml.
280
-
281
- int id = item.getItemId();
282
-
283
-
284
-
285
- //noinspection SimplifiableIfStatement
286
-
287
- if (id == R.id.action_settings) {
288
-
289
- return true;
290
-
291
- }
292
-
293
-
294
-
295
- return super.onOptionsItemSelected(item);
296
-
297
- }
298
-
299
-
300
-
301
- @SuppressWarnings("StatementWithEmptyBody")
302
-
303
- @Override
304
-
305
- public boolean onNavigationItemSelected(MenuItem item) {
306
-
307
- // Handle navigation view item clicks here.
308
-
309
- int id = item.getItemId();
310
-
311
- Fragment fragment = null;
312
-
313
- Class fragmentClass = null;
314
-
315
-
316
-
317
- if (id == R.id.nav_Home) {
318
-
319
- fragmentClass = HomeFragment.class;
320
-
321
-
322
-
323
- // Handle the camera action
324
-
325
- } else if (id == R.id.nav_Day) {
326
-
327
- fragmentClass = DayFragment.class;
328
-
329
-
330
-
331
- } else if (id == R.id.nav_List) {
332
-
333
- fragmentClass = ListFragment.class;
334
-
335
-
336
-
337
- } else if (id == R.id.nav_manage) {
338
-
339
- fragmentClass = HomeFragment.class;
340
-
341
-
342
-
343
- } else if (id == R.id.nav_share) {
344
-
345
- fragmentClass = HomeFragment.class;
346
-
347
-
348
-
349
-
350
-
351
- }
352
-
353
- try {
354
-
355
- fragment = (Fragment) fragmentClass.newInstance();
356
-
357
- } catch (Exception e) {
358
-
359
- e.printStackTrace();
360
-
361
- }
362
-
363
- android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
364
-
365
- fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
366
-
367
-
368
-
369
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
370
-
371
- drawer.closeDrawer(GravityCompat.START);
372
-
373
- return true;
321
+ public void onDetach() {
322
+
323
+ super.onDetach();
324
+
325
+ mListener = null;
326
+
327
+ }
328
+
329
+
330
+
331
+ /**
332
+
333
+ * This interface must be implemented by activities that contain this
334
+
335
+ * fragment to allow an interaction in this fragment to be communicated
336
+
337
+ * to the activity and potentially other fragments contained in that
338
+
339
+ * activity.
340
+
341
+ * <p>
342
+
343
+ * See the Android Training lesson <a href=
344
+
345
+ * "http://developer.android.com/training/basics/fragments/communicating.html"
346
+
347
+ * >Communicating with Other Fragments</a> for more information.
348
+
349
+ */
350
+
351
+ public interface OnFragmentInteractionListener {
352
+
353
+ // TODO: Update argument type and name
354
+
355
+ void onFragmentInteraction(Uri uri);
374
356
 
375
357
  }
376
358
 
377
359
  }
378
360
 
379
-
380
-
381
-
382
-
383
361
  ```
384
362
 
385
363
 

2

エラーメッセージの欄にAndroid Studioのログキャットのエラーメッセージを追加しました。

2018/08/19 01:05

投稿

Nustin053
Nustin053

スコア12

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,85 @@
52
52
 
53
53
  アプリが停止しました (スマートフォン)
54
54
 
55
+
56
+
55
- Android studioでは特に表示はありません
57
+ Android studio
58
+
59
+ ```実行
60
+
61
+
62
+
63
+ 08/04 23:46:28: Launching app
64
+
65
+ $ adb install-multiple -r -t -p com.websarver.wings.android.mamaraku C:\Users\nagi0\Desktop\MamaRaku\app\build\intermediates\split-apk\debug\slices\slice_2.apk
66
+
67
+ Split APKs installed
68
+
69
+ $ adb shell am start -n "com.websarver.wings.android.mamaraku/com.websarver.wings.android.mamaraku.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
70
+
71
+ Client not ready yet..Waiting for process to come online
72
+
73
+ Waiting for process to come online
74
+
75
+ Connected to process 19960 on device sony-e6853-CB5A29KZYU
76
+
77
+ Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
78
+
79
+ V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
80
+
81
+ V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
82
+
83
+ mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
84
+
85
+ V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@2ff37f8
86
+
87
+ D/AndroidRuntime: Shutting down VM
88
+
89
+ E/AndroidRuntime: FATAL EXCEPTION: main
90
+
91
+ Process: com.websarver.wings.android.mamaraku, PID: 19960
92
+
93
+ java.lang.RuntimeException: com.websarver.wings.android.mamaraku.MainActivity@8355733 must implement OnFragmentInteractionListener
94
+
95
+ at com.websarver.wings.android.mamaraku.HomeFragment.onAttach(HomeFragment.java:83)
96
+
97
+ at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1372)
98
+
99
+ at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1188)
100
+
101
+ at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1071)
102
+
103
+ at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115)
104
+
105
+ at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
106
+
107
+ at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
108
+
109
+ at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
110
+
111
+ at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
112
+
113
+ at android.os.Handler.handleCallback(Handler.java:751)
114
+
115
+ at android.os.Handler.dispatchMessage(Handler.java:95)
116
+
117
+ at android.os.Looper.loop(Looper.java:241)
118
+
119
+ at android.app.ActivityThread.main(ActivityThread.java:6274)
120
+
121
+ at java.lang.reflect.Method.invoke(Native Method)
122
+
123
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
124
+
125
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
126
+
127
+ I/art: Do partial code cache collection, code=24KB, data=29KB
128
+
129
+ I/art: After code cache collection, code=17KB, data=25KB
130
+
131
+ Increasing code cache capacity to 128KB
132
+
133
+ ```
56
134
 
57
135
 
58
136
 
@@ -306,81 +384,7 @@
306
384
 
307
385
 
308
386
 
309
- ```実行
387
+
310
-
311
-
312
-
313
- 08/04 23:46:28: Launching app
314
-
315
- $ adb install-multiple -r -t -p com.websarver.wings.android.mamaraku C:\Users\nagi0\Desktop\MamaRaku\app\build\intermediates\split-apk\debug\slices\slice_2.apk
316
-
317
- Split APKs installed
318
-
319
- $ adb shell am start -n "com.websarver.wings.android.mamaraku/com.websarver.wings.android.mamaraku.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
320
-
321
- Client not ready yet..Waiting for process to come online
322
-
323
- Waiting for process to come online
324
-
325
- Connected to process 19960 on device sony-e6853-CB5A29KZYU
326
-
327
- Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
328
-
329
- V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
330
-
331
- V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
332
-
333
- mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
334
-
335
- V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@2ff37f8
336
-
337
- D/AndroidRuntime: Shutting down VM
338
-
339
- E/AndroidRuntime: FATAL EXCEPTION: main
340
-
341
- Process: com.websarver.wings.android.mamaraku, PID: 19960
342
-
343
- java.lang.RuntimeException: com.websarver.wings.android.mamaraku.MainActivity@8355733 must implement OnFragmentInteractionListener
344
-
345
- at com.websarver.wings.android.mamaraku.HomeFragment.onAttach(HomeFragment.java:83)
346
-
347
- at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1372)
348
-
349
- at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1188)
350
-
351
- at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1071)
352
-
353
- at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115)
354
-
355
- at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
356
-
357
- at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
358
-
359
- at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
360
-
361
- at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
362
-
363
- at android.os.Handler.handleCallback(Handler.java:751)
364
-
365
- at android.os.Handler.dispatchMessage(Handler.java:95)
366
-
367
- at android.os.Looper.loop(Looper.java:241)
368
-
369
- at android.app.ActivityThread.main(ActivityThread.java:6274)
370
-
371
- at java.lang.reflect.Method.invoke(Native Method)
372
-
373
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
374
-
375
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
376
-
377
- I/art: Do partial code cache collection, code=24KB, data=29KB
378
-
379
- I/art: After code cache collection, code=17KB, data=25KB
380
-
381
- Increasing code cache capacity to 128KB
382
-
383
- ```
384
388
 
385
389
 
386
390
 

1

実行時のメッセージを追記しました

2018/08/18 15:20

投稿

Nustin053
Nustin053

スコア12

test CHANGED
File without changes
test CHANGED
@@ -304,61 +304,81 @@
304
304
 
305
305
  ```
306
306
 
307
- ```>activity_main.xml
308
-
309
- <?xml version="1.0" encoding="utf-8"?>
310
-
311
- <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
312
-
313
- xmlns:app="http://schemas.android.com/apk/res-auto"
314
-
315
- xmlns:tools="http://schemas.android.com/tools"
316
-
317
- android:id="@+id/drawer_layout"
318
-
319
- android:layout_width="match_parent"
320
-
321
- android:layout_height="match_parent"
322
-
323
- android:fitsSystemWindows="true"
324
-
325
- tools:openDrawer="start">
326
-
327
-
328
-
329
- <include
330
-
331
- layout="@layout/app_bar_main"
332
-
333
- android:layout_width="match_parent"
334
-
335
- android:layout_height="match_parent" />
336
-
337
-
338
-
339
- <android.support.design.widget.NavigationView
340
-
341
- android:id="@+id/nav_view"
342
-
343
- android:layout_width="wrap_content"
344
-
345
- android:layout_height="match_parent"
346
-
347
- android:layout_gravity="start"
348
-
349
- android:fitsSystemWindows="true"
350
-
351
- app:headerLayout="@layout/nav_header_main"
352
-
353
- app:menu="@menu/activity_main_drawer" />
354
-
355
-
356
-
357
- </android.support.v4.widget.DrawerLayout>
358
-
359
-
360
-
361
-
307
+
308
+
309
+ ```実行
310
+
311
+
312
+
313
+ 08/04 23:46:28: Launching app
314
+
315
+ $ adb install-multiple -r -t -p com.websarver.wings.android.mamaraku C:\Users\nagi0\Desktop\MamaRaku\app\build\intermediates\split-apk\debug\slices\slice_2.apk
316
+
317
+ Split APKs installed
318
+
319
+ $ adb shell am start -n "com.websarver.wings.android.mamaraku/com.websarver.wings.android.mamaraku.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
320
+
321
+ Client not ready yet..Waiting for process to come online
322
+
323
+ Waiting for process to come online
324
+
325
+ Connected to process 19960 on device sony-e6853-CB5A29KZYU
326
+
327
+ Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
328
+
329
+ V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
330
+
331
+ V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
332
+
333
+ mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
334
+
335
+ V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@2ff37f8
336
+
337
+ D/AndroidRuntime: Shutting down VM
338
+
339
+ E/AndroidRuntime: FATAL EXCEPTION: main
340
+
341
+ Process: com.websarver.wings.android.mamaraku, PID: 19960
342
+
343
+ java.lang.RuntimeException: com.websarver.wings.android.mamaraku.MainActivity@8355733 must implement OnFragmentInteractionListener
344
+
345
+ at com.websarver.wings.android.mamaraku.HomeFragment.onAttach(HomeFragment.java:83)
346
+
347
+ at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1372)
348
+
349
+ at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1188)
350
+
351
+ at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1071)
352
+
353
+ at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115)
354
+
355
+ at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
356
+
357
+ at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
358
+
359
+ at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
360
+
361
+ at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
362
+
363
+ at android.os.Handler.handleCallback(Handler.java:751)
364
+
365
+ at android.os.Handler.dispatchMessage(Handler.java:95)
366
+
367
+ at android.os.Looper.loop(Looper.java:241)
368
+
369
+ at android.app.ActivityThread.main(ActivityThread.java:6274)
370
+
371
+ at java.lang.reflect.Method.invoke(Native Method)
372
+
373
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
374
+
375
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
376
+
377
+ I/art: Do partial code cache collection, code=24KB, data=29KB
378
+
379
+ I/art: After code cache collection, code=17KB, data=25KB
380
+
381
+ Increasing code cache capacity to 128KB
362
382
 
363
383
  ```
364
384
 
@@ -366,6 +386,10 @@
366
386
 
367
387
 
368
388
 
389
+
390
+
391
+
392
+
369
393
  ### 試したこと
370
394
 
371
395