0

我打电话给这段代码 getSupportFragmentManager() .beginTransaction() .replace(R.id.menu_frame_two, new SlideRight()) .commit();

导致

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}.

有什么帮助吗?

4

2 回答 2

0

该错误告诉您当前布局中没有menu_frame_two视图。仔细检查你没有任何错字。

于 2013-10-14T07:17:31.100 回答
0
// 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);
        }
    }
于 2013-10-14T07:25:13.657 回答