java.lang.NullPointerException:尝试调用虚拟方法'void android.support.design.widget.BottomNavigationView

时间:2019-04-11 01:54:09

标签: bottomnavigationview

底部导航没有获取我的视图。我已经制作了此底部导航所需的每个片段,但我不知道为什么底部导航仍指向nullpointerexecption。

我已经尽我所能在这个类似问题中找到的一切。

    BottomNavigationView bottomNav = (BottomNavigationView)findViewById(R.id.bottom_navigation);
    bottomNav.setOnNavigationItemSelectedListener(navListener);

    if(savedInstanceState==null){
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
    }
}

private BottomNavigationView.OnNavigationItemSelectedListener navListener =  new BottomNavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
        Fragment selectedFragment = null;


        switch (menuItem.getItemId()) {
            case R.id.nav_home:
                selectedFragment = new HomeFragment();
                break;
            case R.id.nav_profile:
                selectedFragment = new SettingFragment();
                break;
        }

        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                selectedFragment).commit();

        return true;
    }
};

0 个答案:

没有答案