我无法打开片段

时间:2019-07-23 17:56:09

标签: android fragment navigationview

我无法在NavigationView中打开片段

我认为新图书馆工作不那么老图书馆 新库:androidx.fragment.app.Fragment 旧库:android.support.v4.app.Fragment

   public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_home) {
        fragmentClass = information.class;
    } /*else if (id == R.id.nav_find1) {

    } else if (id == R.id.nav_reg) {

    } else if (id == R.id.nav_vhod) {

    } else if (id == R.id.nav_exit) {

    }*/
    try {
        fragment = (Fragment) fragmentClass.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Вставляем фрагмент, заменяя текущий фрагмент
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
dependencies:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'

请帮助我

  

错误:java.lang.IllegalArgumentException:找不到ID 0x7f080032(com.example.natalietutoring:id /容器)的片段信息{23f47c33#0 id = 0x7f080032}

0 个答案:

没有答案