nishant.dande
nishant.dande

Reputation: 121

Error in Fragment

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?

Upvotes: 2

Views: 2830

Answers (1)

telkins
telkins

Reputation: 10540

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.

Upvotes: 5

Related Questions