前提
androidstudioについて質問します。
navigationdrawerを実装しようとしたらエラーが出てきました。
実現したいこと
エラーの解消
発生している問題・エラーメッセージ
Caused by: android.view.InflateException: Binary XML file line #250 in local.hal.st31.android.studyapplication:layout/activity_problem: Binary XML file line #10 in local.hal.st31.android.studyapplication:layout/content_problem: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #10 in local.hal.st31.android.studyapplication:layout/content_problem: Error inflating class fragment Caused by: java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f090292, tag null, or parent id 0xffffffff with another fragment for androidx.navigation.fragment.NavHostFragment
該当のソースコード
ProblemActivity
1 private AppBarConfiguration mAppBarConfiguration; 2 private ActivityProblemBinding binding; 3 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.activity_problem); 8//ここでエラーが発生 9 binding = ActivityProblemBinding.inflate(getLayoutInflater()); 10 setContentView(binding.getRoot()); 11 12 setSupportActionBar(binding.appBarProblem.toolbar); 13 DrawerLayout drawer = binding.drawerLayout; 14 NavigationView navigationView = binding.navView; 15 // Passing each menu ID as a set of Ids because each 16 // menu should be considered as top level destinations. 17 mAppBarConfiguration = new AppBarConfiguration.Builder( 18 R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow) 19 .setOpenableLayout(drawer) 20 .build(); 21 NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_problem); 22 NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); 23 NavigationUI.setupWithNavController(navigationView, navController); 24}
試したこと
エラーの意味を調べてみたら、一番下のエラーはフラグメント重複しているエラーでした。
内容がまったく同じのxmlがあったのでそれが原因かと思い消したのですがエラーは変わりませんでした。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/12/05 05:00
2022/12/05 05:30