title: Call Fragment method from Activity
body: <p>I need to call a method inside a fragment in onResume activity, but always shows FC with this error:</p>
  
  <pre><code>06-15 14:59:58.496: E/AndroidRuntime(28904): FATAL EXCEPTION: main
  06-15 14:59:58.496: E/AndroidRuntime(28904): Process: com.carlosdiaz.tfm_usuarios, PID: 28904
  06-15 14:59:58.496: E/AndroidRuntime(28904): java.lang.RuntimeException: Unable to resume activity {com.carlosdiaz.tfm_usuarios/com.carlosdiaz.tfm_usuarios.Grupos}: java.lang.NullPointerException
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2774)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2803)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2238)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.os.Handler.dispatchMessage(Handler.java:102)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.os.Looper.loop(Looper.java:136)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.main(ActivityThread.java:5001)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at java.lang.reflect.Method.invoke(Method.java:515)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at dalvik.system.NativeStart.main(Native Method)
  06-15 14:59:58.496: E/AndroidRuntime(28904): Caused by: java.lang.NullPointerException
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at com.carlosdiaz.tfm_usuarios.Grupos.onResume(Grupos.java:52)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.Activity.performResume(Activity.java:5310)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2764)
  06-15 14:59:58.496: E/AndroidRuntime(28904):    ... 12 more
  </code></pre>
  
  <p>I don't know what can I do.</p>
  
  <p>This is mi OnCreate &amp; onResume methods:</p>
  
  <pre><code>public class Grupos extends Activity {
  
      PlaceholderFragment fragment;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_grupos);
  
          fragment = (PlaceholderFragment) getFragmentManager().findFragmentById(R.layout.fragment_grupos);
  
          if (savedInstanceState == null) {
              getFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
      }
  
      @Override
      protected void onResume()
      {
          super.onResume();
          Log.i("Test","Test");
          fragment.myOnResume();
      }
  </code></pre>
  
  <p>...</p>
  
  <p>My method is inside the Fragment class:</p>
  
  <pre><code>public static class PlaceholderFragment extends Fragment {
  ...
  public void myOnResume() {
              GruposTask getGrupos = new GruposTask(PlaceholderFragment.this, getActivity());
              getGrupos.execute(id);
          }
  ...
  </code></pre>
  
  <p>Thank You in advance!</p>
  
  <p><strong>edit:</strong></p>
  
  <p>now im trying to create the fragment in the activity xml to call it later from oncreate() this way:</p>
  
  <pre><code>PlaceholderFragment mainFragment = (PlaceholderFragment)getFragmentManager().findFragmentById(R.id.listGroup);
  </code></pre>
  
  <p>this is the activity layout:</p>
  
  <pre><code>   xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.carlosdiaz.tfm_usuarios.Grupos"
      tools:ignore="MergeRootFrame"&gt;
      &lt;fragment class="com.carlosdiaz.tfm_usuarios.Grupos.PlaceholderFragment"
              android:id="@+id/listGroup"
              android:layout_weight="1"
              android:layout_width="0dp"
              android:layout_height="match_parent" /&gt;
   &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>But now Im having this error:</p>
  
  <pre><code>06-15 19:20:15.956: E/AndroidRuntime(7424): FATAL EXCEPTION: main
  06-15 19:20:15.956: E/AndroidRuntime(7424): Process: com.carlosdiaz.tfm_usuarios, PID: 7424
  06-15 19:20:15.956: E/AndroidRuntime(7424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.carlosdiaz.tfm_usuarios/com.carlosdiaz.tfm_usuarios.Grupos}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.os.Handler.dispatchMessage(Handler.java:102)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.os.Looper.loop(Looper.java:136)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread.main(ActivityThread.java:5001)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at java.lang.reflect.Method.invoke(Method.java:515)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at dalvik.system.NativeStart.main(Native Method)
  06-15 19:20:15.956: E/AndroidRuntime(7424): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Activity.setContentView(Activity.java:1929)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at com.carlosdiaz.tfm_usuarios.Grupos.onCreate(Grupos.java:39)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Activity.performCreate(Activity.java:5231)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     ... 11 more
  06-15 19:20:15.956: E/AndroidRuntime(7424): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.carlosdiaz.tfm_usuarios.Grupos.PlaceholderFragment: make sure class name exists, is public, and has an empty constructor that is public
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Fragment.instantiate(Fragment.java:597)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Fragment.instantiate(Fragment.java:561)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Activity.onCreateView(Activity.java:4778)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     ... 21 more
  06-15 19:20:15.956: E/AndroidRuntime(7424): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.carlosdiaz.tfm_usuarios.Grupos.PlaceholderFragment" on path: DexPathList[[zip file "/data/app/com.carlosdiaz.tfm_usuarios-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.carlosdiaz.tfm_usuarios-2, /vendor/lib, /system/lib]]
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     at android.app.Fragment.instantiate(Fragment.java:583)
  06-15 19:20:15.956: E/AndroidRuntime(7424):     ... 24 more
  </code></pre>