我有滑塊菜單displayview方法爲:的Android片段從導航抽屜切換導致應用程序退出
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new HomeFragment();
FragmentManager fm = getSupportFragmentManager();
String tag = fragment.getTag(); // instance method of a to get a tag
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_container, fragment, tag);
ft.addToBackStack(tag);
ft.commit();
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
drawerListView.setItemChecked(position, true);
drawerListView.setSelection(position);
setTitle(navMenuTitles[position]);
drawer.closeDrawer(drawerListView);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
我有一個名爲home_fragment其代碼後面是HomeFragment.java
當我點擊該片段片段首先它工作正常,但點擊索引0旁邊的菜單時,出現如下錯誤:
Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' on a null object reference
我在做什麼錯?謝謝。
這是我遇到的錯誤:
case OP_REMOVE: {
Fragment f = op.fragment;
f.mNextAnim = exitAnim;
mManager.removeFragment(f, transition, transitionStyle);
} break;
此代碼存在於BackStackRecord.java
你在哪裏使用mNextAnim? – freddieptf