我需要帮助。我得到了Crashlytics的崩溃:没有找到id的片段
Fatal Exception: java.lang.IllegalArgumentException: No view found for id 0x7f0f016c (com.my.my:id/fragment_root_layout) for fragment a{2e8d61e1 #4 id=0x7f0f016c fragment_tag}
我使用片段进入片段。在父片段的OnCreate方法中,我使用帮助FragmentManager添加子片段。我有一个想法,问题是在OnCreate方法中添加子片段,并且需要在OnCreateView中执行此操作。但我不确定。事情是我不能再现这次崩溃,但我在Crashlytic上得到这个崩溃。 父级片段装载的所有视图都有一个ID。只有当我在OnCreateView方法中膨胀不正确的布局时,我才能重现此崩溃,但在实时构建中不会发生这种情况。 请给我一个建议。
编辑:添加子片段
准则@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogUtils.verbose(TAG, "displayOverlayFragment: attempt to add a fragment using FragmentTransaction");
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
OverlayFragment overlayFragment = new OverlayFragment();
fragmentTransaction.add(R.id.fragment_root_layout, overlayFragment, FRAGMENT_TAG);
fragmentTransaction.commit();
}
代码onCreateView的:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(getLayoutResId(), container, false);
mRecyclerView = initRecyclerView(view);
mProgressBar = view.findViewById(R.id.progressBar);
mProgressBarLabel = (TextView) view.findViewById(R.id.progressBarLabel);
}
return view;
}
@Override
protected int getLayoutResId() {
return R.layout.fragment_favorites;
}
你确定存在一个ID为'fragment_root_layout'的视图吗? –
尝试将子片段添加到父片段的“onViewCreated”方法中。在此之前,您不应使用父母版面中的任何ID。 – hibob
发布你的代码到目前为止你已经尝试过吗? – FAT