In an app with a side menu, when I click on one of its items, I want to load the same as clicking on another button (also in a fragment) of the application. To do this I create an object of that class and call its corresponding method from onNavigationItemSelected (), but when entering the method, it stops at:
ConnectivityManager connectivityManager = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
with the following error message:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference
This is how I call the method
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.miInstalaciones) {
MainMenu_fragment mainMenu_fragment = new MainMenu_fragment();
mainMenu_fragment.getTiposInstalacion();