简体   繁体   中英

calling new fragment error with no view found by id

im calling this code getSupportFragmentManager() .beginTransaction() .replace(R.id.menu_frame_two, new SlideRight()) .commit();

causing

10-14 07:12:57.895: E/AndroidRuntime(2293): java.lang.IllegalArgumentException: No view found for id 0x7f07010e (com.test:id/menu_frame_two) for fragment SlideRight{a7754e48 #0 id=0x7f07010e}.

Any help?

The error is telling you that there's no menu_frame_two view in your current layout. Double check you don't have any typo.

// try this
    SlideRight fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yourxml);

        if (savedInstanceState == null) {
            // Add the fragment on initial activity setup
            fragment = new SlideRight();
            getSupportFragmentManager().beginTransaction().add(android.R.id.menu_frame_two, fragment).commit();
        } else {
            // Or set the fragment from restored state info
            fragment = (SlideRight) getSupportFragmentManager().findFragmentById(android.R.id.menu_frame_two);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM