拋出:IllegalArgumentException:LinearLayoutManager已經連接到 RecyclerView拋出:IllegalArgumentException:LinearLayoutManager已經連接到RecyclerView
,當我嘗試設置LayoutManager
我RecyclerView
,它說我得到這個Exception
LinearLayoutManager is already attached
但在爲我的RecyclerView設置LinearLayoutManager之前,我已經檢查過我的RecyclerView
是否包含LinearLayout
或不包含
像下面的圖片,你會看到RecyclerView.LayoutManager m
= NULL,但仍異常拋出
RecyclerView.LayoutManager m = recyclerView.getLayoutManager();
if(recyclerView.getLayoutManager() != null){
return;
}
try {
recyclerView.setLayoutManager(layoutManager);
}catch (Exception e){
Log.e("AA", "setRecyclerViewLayoutManager: ", e);
}
我不知道爲什麼會這樣。如何防止爲我的RecyclerView
設置新的LinearLayoutManager
?
這裏是logcat的
java.lang.IllegalArgumentException: LayoutManager [email protected] is already attached to a RecyclerView: android.support.v7.widget.RecyclerView{1cbedba4 VFED.... .......D 0,0-1080,1181 #7f0d00b6 app:id/recycler_news}
at android.support.v7.widget.RecyclerView.setLayoutManager(RecyclerView.java:1087)
at com.toong.map.utils.BindingUtils.setRecyclerViewLayoutManager(BindingUtils.java:76)
at com.toong.map.databinding.FragmentNewsBaseBinding.executeBindings(FragmentNewsBaseBinding.java:191)
at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:355)
at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:172)
at android.databinding.ViewDataBinding$7.doFrame(ViewDataBinding.java:238)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:765)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
你有多個房車嗎? – Blackbelt
@Blackbelt不,我只有1'RecyclerView' –
分享完整代碼 –