[英]calling new fragment error with no view found by id
我正在调用此代码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}.
有什么帮助吗?
错误告诉您当前布局中没有menu_frame_two
视图。 仔细检查您没有错字。
// 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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.