Continue to the next step in android Kotlin; Unresolved class reference

I am trying to proceed to the next action using my button listener and it says unresolved reference java Here is my code:

btn?.setOnClickListener(object: View.OnClickListener {
      override fun onClick(view: View): Unit {
         val intent = Intent(this@MainActivity,NextActivity::class.java)
            Toast.makeText(this@MainActivity,"helllo",Toast.LENGTH_LONG).show()
         }
      })

NOTE. Here is NextActivityalso a kotlin file.

The error shown in the image

enter image description here

+1
source share
4 answers

Try either updating Kotlin to the latest version, or adding a link to kotlin-reflect below the stdlib dependency (it will look like this :):

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
+1
source
btn?.setOnClickListener {
   startActivity(Intent(this, NextActivity::class.java))
}
+2
source

@Hong Duan

You might need to add the kotlin stdlib parameter to your gradle script

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+1
source

If you use anko , you can use the following

val intent = IntentFor<NextActivity>()
0
source

Source: https://habr.com/ru/post/1683403/


All Articles