title: How to access a method in fragment class from parent Activity?
body: <p>I am implementing a database as I need to prepare the list or update it everytime I make some changes. I have a fragment on top of mainActivity and I can't perform the operations within the <code>MainActivity</code> so some of the operations are to be done in <code>MainActivity</code> and others in the <code>fragment class</code>.
  So in the fragment class which extends fragment has a method called <code>preparelist()</code>, which updates the database and populate the data.
  In my mainactivity I am performing a delete operations using the default <code>overflow</code> menu item, <strong>but here I need to call the <code>preparelist()</code> method in order to display the performed operations or the app has to be closed in order to diplay the operation that has been performed</strong></p>
  
  <p>I have tried the following code which is on the web</p>
  
  <pre><code>MyFragment fragment= (MyFragment)getSupportFragmentManager().findFragmentById(R.id.frag);
  ( (MyFragment)fragment).prepareList();
  </code></pre>
  
  <p>but this shows error</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method...on a null object reference
  </code></pre>
  
  <blockquote>
    <p>Basically what I want to know is how do I call the <code>preparelist()</code> method within my <code>MainActivity</code> without making any other abstract class or anything like that</p>
  </blockquote>