Variable is declared as var but compiler is saying it val
Asked Answered
A

1

0

Compiler is giving me the error

Error:(97, 17) Val cannot be reassigned

but the variable is declared as var.

Edit: You can see comments in my code. When i assign rcv = recyclerView and
chkStrictSearch = checkBox I get red underline here with above error message tooltip

Below is my code:

private var rcv: RecyclerView? = null
private var chkStrictSearch: android.widget.CheckBox? = null  

private fun getMainView(): View{
    return with(context){
        frameLayout{
            lparams(width = matchParent, height = matchParent)
            //Error is below - val cannot be reassign
            rcv = recyclerView{
                lparams(width = matchParent, height = matchParent)
                setPadding(0, resources.getDimension(R.dimen.toolbar_height).toInt(), 0, dip(48))
                clipToPadding = false
            }
           //and here - val cannot be reassign
            chkStrictSearch = checkBox{
                text = "Strict Search"
            }.lparams(width = wrapContent, height = wrapContent){
                marginEnd = dip(24)
                bottomMargin = dip(50)
                gravity = Gravity.BOTTOM
            }
        }
    }
}  
Athletics answered 28/6, 2017 at 10:41 Comment(0)
P
3

Seems like a bug in the static code analysis or it may be caused by incremental compiling. Try to rebuild/clean the project.

Or try this:

private fun getMainView(): View {
    return with(context) {
        frameLayout {
           rcv = null
        }
    }
}

If the compilation works now, add back your original code and compile again.

Pliner answered 28/6, 2017 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.