我有抽屜式導航菜單,我有碎片Frag1,Frag2和Frag3。 Frag2正在被Frag21,Frag21和Frag22等替代。 如果我從Frag22到Frag21和Frag2按後退按鈕的應用程序關閉properly.But如果我直接從Frag22到Frag1並嘗試關閉該應用程序,它得到墜毀而我會得到錯誤應用程序崩潰時後退按鈕被按下片段:拋出:IllegalArgumentException:沒有查看發現ID 0x7f0f00c4
E/AndroidRuntime :FATAL EXCEPTION:main java.lang.IllegalArgumentException:在android.support.v4.app中沒有找到針對片段CategoriesDisplayList {4260ca00#1 id = 0x7f0f00c4} 的id 0x7f0f00c4(com.NuSS.MyPAS:id/root_frame)的視圖。 FragmentManagerImpl.moveToState在android.support.v4.app.BackStackRecord.popFromBackStack(FragmentManager.java:947) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138) (BackStackRecord.java:960) at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1553) at android.support.v4.app.FragmentManagerImpl $ 2.run(FragmentManager.java:497) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501) at android.support.v4.app.FragmentManagerImpl $ 1.run(FragmentManager.java:458) at android.os.Handler.handleCallback(Handler .java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java :5306) 在java.lang.reflect.Method.invokeNative(本地方法) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit。 Java的:1102) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 在dalvik.system.NativeStart.main(本機方法)
也給
**@Override
public void onBackPressed() {
if(fragmentManager.getBackStackEntryCount() != 0) {
fragmentManager.popBackStack();
} else {
super.onBackPressed();
}
}**
主要片段活動中的
。
請給予解決方案堅持了這個錯誤的幾天。
UPDATE
代碼段
RootFragment
公共類RootFragment延伸片段{
private static final String TAG = "RootFragment";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/* Inflate the layout for this fragment */
View view = inflater.inflate(R.layout.activity_root_fragment, container, false);
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
/*
* When this container fragment is created, we fill it with our first
* "real" fragment
*/
transaction.replace(R.id.root_frame, new CategoriesDisplayList());
transaction.commit();
return view;
}
@Override
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
try {
Fragment fragment = (getFragmentManager()
.findFragmentById(R.id.root_frame));
FragmentTransaction ft = getActivity().getSupportFragmentManager()
.beginTransaction();
ft.remove(fragment);
ft.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
CategoryDisplayList
公共類CategoriesDisplayList延伸片段實現SwipeRefreshLayout。OnRefreshListener {
categoryListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FragmentTransaction trans = getFragmentManager()
.beginTransaction();
trans.replace(R.id.root_frame, new RootFragmentService());
trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
trans.addToBackStack(null);
trans.commit();
}
});
//registerForContextMenu(vendorListView);
return rootView;
}
RootFragmentService
公共類RootFragmentService擴展片段{
private static final String TAG = "RootFragment";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_root_fragment, container, false);
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
/*
* When this container fragment is created, we fill it with our first
* "real" fragment
*/
transaction.replace(R.id.root_frame, new ServicesList());
transaction.commit();
return view;
}
@Override
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
try {
Fragment fragment = (getFragmentManager()
.findFragmentById(R.id.root_frame));
FragmentTransaction ft = getFragmentManager()
.beginTransaction();
ft.remove(fragment);
ft.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
在此先感謝。
http://stackoverflow.com/questions/7508044/android-fragment-no-view-found-for-id –
嗨,你怎麼關閉你的應用程序?只需重複點擊返回按鈕? – NitroNbg
http://stackoverflow.com/questions/28637046/illegalargumentexception-no-view-found-for-id-in-fragments –