友盟報異常窍株,關(guān)于.RecyclerView罩驻。一般解決方法是inflater.inflate參數(shù)改為null或者false捂掰。但是現(xiàn)在正常的都是這么寫的,也不必現(xiàn)想括,所以肯定不是
搜到一個文章:
https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/2796
androidx.recyclerview.widget.RecyclerView
@NonNull
public final VH createViewHolder(@NonNull ViewGroup parent, int viewType) {
try {
TraceCompat.beginSection(TRACE_CREATE_VIEW_TAG);
final VH holder = onCreateViewHolder(parent, viewType);
if (holder.itemView.getParent() != null) {
throw new IllegalStateException("ViewHolder views must not be attached when"
+ " created. Ensure that you are not passing 'true' to the attachToRoot"
+ " parameter of LayoutInflater.inflate(..., boolean attachToRoot)");
}
holder.mItemViewType = viewType;
return holder;
} finally {
TraceCompat.endSection();
}
}
holder.itemView.getParent() != null報的異常陷谱,所以找到這個holder.itemView.getParent() ,網(wǎng)上找的是一般是可能在setEmptyView時出現(xiàn)的問題,所以找到了項目中用到了相關(guān)的
protected View getEmptyView() {
if (emptyView == null) {
emptyView = LayoutInflater.from(this).inflate(R.layout.layout_loading_empty, null);
}
return emptyView;
}
這個emptyView可能不為空烟逊,就做一下處理
protected View getEmptyView() {
ViewGroup elViewGroup = (ViewGroup) emptyView.getParent();
if (elViewGroup != null) {
elViewGroup.removeView(emptyView);
}
if (emptyView == null) {
emptyView = LayoutInflater.from(this).inflate(R.layout.layout_loading_empty, null);
}
return emptyView;
}
這樣就可以了