2

I'm writing programs with a simple Fragment and I got an error as below:

FrameLayout fl=new FrameLayout(this);
fl.setId(0x1024);

setContentView(fl);
FragmentTransaction ftransc=getFragmentManager().beginTransaction();
FragmentTest2 myFragment=new FragmentTest2();
ftransc.add(fl.getId(), myFragment, "FirstFragment");
ftransc.commit();

Under the add method I get a red squiggly line and the following error shows:

The method add(int, Fragment, String in the type FragmentTransaction is not applicable for the arguments (int, FragmentTest2, String).

What am I doing wrong?

1
  • Does your FragmentTest2 extend Fragment? Commented Aug 1, 2012 at 15:24

1 Answer 1

5

This problem usually occurs when you mix up the compatibility package Fragment and the Android Fragment. If you are trying to use the compatibility Fragment, make sure that you import android.support.v4.app.Fragment, otherwise make sure you import android.app.Fragment. Similarly do the same with FragmentTransaction.

Sign up to request clarification or add additional context in comments.

1 Comment

can we use both in same class ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.