1

unreachable statement because of the switch statement on nv = (NavigationView) findViewById(R.id.nav)

     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;

it says that this part of the code is unreachable

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

}
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • which line does it say is unreachable? – nupadhyaya Oct 01 '18 at 00:41
  • 1
    It's hard to answer without seeing more of your code. Without knowing more, I could guess a couple of possibilities: 1. Maybe there's no way for `R.id.menu_don` to be selected (perhaps because something to do with the navigation drawer's menu)? 2. Maybe there's something odd about the switch statement? If you tell us more, we might be able to help. – Rapunzel Van Winkle Oct 01 '18 at 04:31
  • is you navigation drawer functionality exists in your mainactivity or separate class? if its in separate class then you should pass context from activity to navigation drawer class then write like this on click : Intent imMenuDon = new Intent(context, DonActivity.class); startActivity(imMenuDon); if its exists inside of mainActivity then write like this : Intent imMenuDon = new Intent(MainActivity.this, DonActivity.class); startActivity(imMenuDon); – unzila Oct 01 '18 at 04:37
  • Correction in title – Aniruddh Parihar Oct 01 '18 at 10:42

0 Answers0