Skip to content Skip to sidebar Skip to footer

Bottomnavigationview Is Null

I have a runtime exception when implementing BottomNavigationView, Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.material.bo

Solution 1:

You are trying to find the BottomNavigationView before setting the activity view. You should set content view first.

Reorganize your code as follow

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

    // everything other
}

Solution 2:

hi you didn't give any reference to the XML file include these lines at the start of onCreate method

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Post a Comment for "Bottomnavigationview Is Null"