尝试从NavigationDrawer打开新活动,但显示无法访问的语句

时间:2018-10-01 00:23:43

标签: android switch-statement navigation-drawer unreachable-statement

由于nv =(NavigationView)findViewById(R.id.nav)上的switch语句而导致无法到达的语句

     nv = (NavigationView) findViewById(R.id.nav);

    nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.menu_posts:
                    Intent iMenuPosts = new Intent(getApplicationContext(), PostsActivity.class);
                    startActivity(iMenuPosts);
                    break;

它说这部分代码无法访问

case R.id.menu_don:
                    Intent imMenuDon = new Intent(getApplicationContext(), DonActivity.class);
                    startActivity(imMenuDon);
            }
            return true;
        }
    });
}

}

0 个答案:

没有答案