coder_For_Life22 coder_For_Life22 - 6 months ago 570
Android Question

Android Fragment no view found for ID?

I have a fragment I am trying to add into a view.

FragmentManager fragMgr=getSupportFragmentManager();
feed_parser_activity content = (feed_parser_activity)fragMgr
.findFragmentById(R.id.feedContentContainer);
FragmentTransaction xaction=fragMgr.beginTransaction();

if (content == null || content.isRemoving()) {
content=new feed_parser_activity(item.getLink().toString());
xaction
.add(R.id.feedContentContainer, content)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
Log.e("Abstract", "DONE");
}


When this code is executed I get the following error in debug..

java.lang.IllegalArgumentException: No view found for id 0x7f080011
for fragment feed_parser_activity{41882f50 #2 id=0x7f080011}


feed_parser_activity
is a Fragment that is set to Fragment layout in xml.

I am using a FragmentActivity to host the Fragment Layout holding the
feed_parser_layout
.

Am I coding this correctly above?

Answer

I was having this problem too, until I realized that I had specified the wrong layout in setContentView() of the onCreate() method of the FragmentActivity.

The id passed into FragmentTransaction.add(), in your case R.id.feedContentContainer, must be a child of the layout specified in setContentView().

You didn't show us your onCreate() method, so perhaps this is the same problem.