title: NullPointerException when calling a Fragment method from Activity?
body: <p>I'm getting a <code>NullPointerException</code> when calling a Fragment's method.</p>
  
  <p>In my <strong>MainActivity:</strong></p>
  
  <pre><code>  AddTab fragObj = (AddTab) getSupportFragmentManager().findFragmentById(R.layout.fragment_add);
   fragObj.receiveURL(sharedText);
  </code></pre>
  
  <p>receiveURL() is a method in my Fragment AddTab.</p>
  
  <p>I'm using <code>pagerslidingtabstrip</code> in my app to create tabs and that <code>Fragment</code> is created by it's <code>PagerAdapter</code> class.</p>
  
  <p>I'm not sure if it is right to create a new instance of the Tab, because already one exists. I don't know how to get access to that instance as well.</p>
  
  <p>I'm getting a <code>NullPointerException</code> now. Can anyone please help me on how to call that method in the fragment?</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p><strong>AddTab.java :</strong></p>
  
  <pre><code>public class AddTab extends Fragment implements View.OnClickListener {
  </code></pre>
  
  <p>...</p>
  
  <p>}</p>
  
  <p><strong>fragment_add.xml :</strong></p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" tools:context="com.example.nikhil.amazon1.Add"&gt;
  
  
      &lt;EditText
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/editText"
          android:text="@string/URL"
          android:hint="@string/hint"
          android:layout_marginTop="200dp"
          android:layout_gravity="center_horizontal|top" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/Track"
          android:id="@+id/button"
          android:layout_gravity="center" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>