我需要幫助。我得到了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