簡體   English   中英

智能轉換為“RecyclerView”是不可能的,因為“recentRecycler”是一個可變屬性,此時可能已更改

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM