1

I am using bottom navigation in my layout but when I try to write an on Click for it in my main activity oncreate it gives me an exception:

Attempt to invoke virtual method on a null object reference private BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav);

    super.onCreate(savedInstanceState);
    bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
        @Override
        public void onNavigationItemReselected(@NonNull MenuItem item) {

        }
    });
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108

1 Answers1

3

change this

    @Override
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav);
    bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
        @Override
        public void onNavigationItemReselected(@NonNull MenuItem item) {

        }
    });
AskNilesh
  • 58,437
  • 15
  • 99
  • 129