Reputation: 419
I am trying to show three different fragments on an
Activity
but when I run my code, my app crashes and the logical does not find any error. what could be the problem?
This is my java file which contains the three fragments
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
public class Gallery extends Activity {
Fragment fragmenta;
Fragment fragmentb;
Fragment fragmentc;
FragmentManager fm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
fm = getFragmentManager();
fragmenta=new FragmentA();
fragmentb=new FragmentB();
fragmentc=new FragmentC();
fragmenta=(Fragment)getFragmentManager().findFragmentById(R.layout.fragmenta);
fragmentb=(Fragment)getFragmentManager().findFragmentById(R.layout.fragmentb);
fragmentc=(Fragment)getFragmentManager().findFragmentById(R.layout.fragmentc);
}
}
Upvotes: 0
Views: 452
Reputation: 27545
If you are using android support v4, your Gallery shall extend FragmentActivity
public class Gallery extends Activity {
should be
public class Gallery extends FragmentActivity {
Upvotes: 1