title: How to call Fragment method from parent activity/Fragment2?
body: <p>I simply want to call a method declared in fragment through parent activity and it gives me the error " Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference"` Please suggest something.</p>
  
  <p>Fragment Method:  </p>
  
  <pre><code>public void loadSpinnerData() {
      Toast.makeText(mActivity, "HELLO", Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>Calling method  from parent actvity:</p>
  
  <pre><code>private void displayView(int position) {
      // update the main content by replacing fragments
      Fragment fragment = null;
      switch (position) {
      case 0:
          fragment = new NoticeBoard();
          break;
      case 1:
          fragment = new Quotes();
          if (fragment instanceof Quotes)
              ((Quotes) fragment).loadSpinnerData();
          break;
      default:
          break;
      }
  
      if (fragment != null) {
          FragmentManager fragmentManager = getFragmentManager();
          fragmentManager.beginTransaction()
                  .replace(R.id.frame_container, fragment).commit();
  
          // update selected item and title, then close the drawer
  
      } else {
          // error in creating fragment
          Log.e("MainActivity", "Error in creating fragment");
      }
  } 
  </code></pre>
  
  <p>my logcat is as follows</p>
  
  <blockquote>
    <p>Logcat error : java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference 05-25 08:46:59.740: E/AndroidRuntime(6152): at app.redalkemi.edublaze.Quotes.loadSpinnerData(Quotes.java:210) </p>
  </blockquote>