0

The error in logcat: E/FragmentManager(7158): No view found for id 0x7f05000d (com.mybiz.mygame:id/fragment_container) for fragment MainMenuFragment{4052d780 #0 id=0x7f05000d}

Ok here is how the app is set up:

Two vars are created:

private static View oGoogleGamesView ;
private static RelativeLayout oViewGroup ;

Then in onCreate:

oViewGroup = new RelativeLayout ( this ) ;
setContentView ( oViewGroup ) ;

LayoutInflater inflater = (LayoutInflater)this.getSystemService ( Context.LAYOUT_INFLATER_SERVICE ) ;       
oGoogleGamesView        = inflater.inflate ( R.layout.ggmain, oViewGroup, false ) ;

And then I try to show the fragment:

// create fragments
mMainMenuFragment = new MainMenuFragment();

// listen to fragment events
mMainMenuFragment.setListener(this);

// add initial fragment (welcome fragment)
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container,
        mMainMenuFragment).commit();

And here it crashes with the error at top. Here is the xml file:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</FrameLayout>

What can I do to show the fragment without crashing?

Hariharan
  • 24,741
  • 6
  • 50
  • 54
Selzier
  • 101
  • 1
  • 6
  • 19

2 Answers2

1

Try this in onCreate method setContentView(R.layout.yourLayout); where yourLayout is xml file containing frameLayout that you have put in your question.

  • Thanks for the reply, however doing this will break my app, I need to keep my ContentView set to oViewGroup. – Selzier Oct 11 '13 at 05:12
1

You set your app view to oViewGroup:

setContentView ( oViewGroup ) ;

Then you inflate another view and leave it dangling:

oGoogleGamesView        = inflater.inflate ( R.layout.ggmain, oViewGroup, false ) ;

To actually have oGoogleGamesView as a layout in your app, you have to add it to the current view, only then can you reference the IDs contained in it:

oViewGroup.addView(oGoogleGamesView, LayoutParams);
Error 454
  • 7,255
  • 2
  • 33
  • 48