我正在尝试替换另一个片段中的片段,我得到一个奇怪的NullPointerException
,请你看看,告诉我你的想法是什么?
这是我的代码:
public class HomeScreenFragment extends Fragment implements FolderViewInterface {
//stuff before this
@Override
public void onFolderOpened(int folder_index) {
System.out.println("THe callback brought me here, passed index:"+folder_index);
Fragment newFragment = new FolderViewFragment();
// consider using Java coding conventions (upper char class names!!!)
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
}
stacktrace:
08-01 16:48:11.587: E/AndroidRuntime(14399): FATAL EXCEPTION: main
08-01 16:48:11.587: E/AndroidRuntime(14399): java.lang.NullPointerException
08-01 16:48:11.587: E/AndroidRuntime(14399): at ro.gebs.captoom.fragments.HomeScreenFragment.onFolderOpened(HomeScreenFragment.java:320)
08-01 16:48:11.587: E/AndroidRuntime(14399): at ro.gebs.captoom.utils.FolderListView.onInterceptTouchEvent(FolderListView.java:48)
08-01 16:48:11.587: E/AndroidRuntime(14399): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
08-01 16:48:11.587: E/AndroidRuntime(14399): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2470)
08-01 16:48:11.587: E/AndroidRuntime(14399): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2212)
08-01 16:48:11.587: E/AndroidRuntime(14399): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2470)
我通过回调来到这里,我在处理触摸事件的ListView上下文中。欢迎任何建议。
答案 0 :(得分:1)
您的FragmentManager看起来为null。尝试使用getChildFragmentManager()。