【发布时间】:2013-12-09 22:17:49
【问题描述】:
我正在尝试使用以下代码打开一个位于另一个 Fragment 内的 Fragment,但它给了我一个空指针异常而没有任何原因。
Fragment newFragment = new SecondFragment();
// 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.menuitem_detail_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
这段代码位于 Fragment (android.support.v4.app.Fragment) 内的 onCreateView 方法内的基本 onItemClickListener 内
关于我可能做错了什么有什么想法吗?
【问题讨论】:
-
抛出的 NPE 是哪一行?
标签: java android android-fragments nullpointerexception android-nested-fragment