![](/img/trans.png)
[英]Smart cast to ‘CLASS!’ is impossible, because ‘VARIABLE’ is a mutable property that could have been changed by this time
[英]Smart cast to 'RecyclerView!' is impossible, because 'recentRecycler' is a mutable property that could have been changed by this time
我嘗試將我的代碼從 java 轉換為 kotlin,因此我遇到了這個錯誤。 我不明白為什么會出現此錯誤
錯誤
Smart cast to 'RecyclerView!' is impossible, because 'recentRecycler' is a mutable property that could have been changed by this time
Smart cast to 'RecyclerView!' is impossible, because 'recentRecycler' is a mutable property that could have been changed by this time
Smart cast to 'RecyclerView!' is impossible, because 'topPlacesRecycler' is a mutable property that could have been changed by this time
Smart cast to 'RecyclerView!' is impossible, because 'topPlacesRecycler' is a mutable property that could have been changed by this time
我只附上了給我一個錯誤的代碼並突出顯示它
private fun setRecentRecycler(recentsDataList: List<RecentsData>) {
recentRecycler = findViewById(R.id.recent_recycler)
val layoutManager: RecyclerView.LayoutManager =
LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)
**recentRecycler.setLayoutManager(layoutManager)** //error
recentsAdapter = RecentsAdapter(this, recentsDataList)
**recentRecycler.setAdapter(recentsAdapter)**//error
}
private fun setTopPlacesRecycler(topPlacesDataList: List<TopPlacesData>) {
topPlacesRecycler = findViewById(R.id.top_places_recycler)
val layoutManager: RecyclerView.LayoutManager =
LinearLayoutManager(this, RecyclerView.VERTICAL, false)
**topPlacesRecycler.setLayoutManager(layoutManager)**//error
topPlacesAdapter = TopPlacesAdapter(this, topPlacesDataList)
**topPlacesRecycler.setAdapter(topPlacesAdapter)**//error
}
private fun setRecentRecycler(recentsDataList: List<RecentsData>) {
recentRecycler = findViewById(R.id.recent_recycler)
topPlacesAdapter = TopPlacesAdapter(this, recentsDataList)
val layoutManager: RecyclerView.LayoutManager =
LinearLayoutManager(this@Fragment/Activity, RecyclerView.HORIZONTAL, false)
}
private fun setTopPlacesRecycler(topPlacesDataList: List<TopPlacesData>) {
topPlacesRecycler = findViewById(R.id.top_places_recycler)
recentsAdapter = RecentsAdapter(this, recentsDataList)
val layoutManager: RecyclerView.LayoutManager =
LinearLayoutManager(this@Fragment/Activity, RecyclerView.VERTICAL, false)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.