Looking at this bit of your code:
clickMe.setOnClickListener(object:View.OnClickListener {
override fun onClick(view: View) {
val aryLength = color.size
val random = Random
val rNum = random.nextInt(aryLength)
screenView.setBackgroundColor(color[rNum])
}
}
val fab: View = findViewById(R.id.fab)
You are getting the first error because you are not properly closing the call to clickMe.setOnClickListener
by providing a )
after the }
on the second to last line. The compiler realizes this on the last line that defines fab
, and so it is that line that the compiler is actually complaining about.
To fix this, add a )
to the second to last line, like this:
clickMe.setOnClickListener(object:View.OnClickListener {
override fun onClick(view: View) {
val aryLength = color.size
val random = Random
val rNum = random.nextInt(aryLength)
screenView.setBackgroundColor(color[rNum])
}
})
val fab: View = findViewById(R.id.fab)
Once you have an initial syntax error, it doesn't really matter what other errors the compiler is producing. Fix this first error and re-evaluate where you're at.
If the code you supply is supposed to be complete...that is, the entire contents of the file MainActivity.kt
is provided, then you are missing a number of closing curlies (}
) at the end of the code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…