Home > Blockchain >  use Intent in Kotlin
use Intent in Kotlin

Time:08-15

When we want to move to another Activity using Intent in Kotlin, it gives this error.

In Intent, it doesn't recognize .java after ::class

look:

enter image description here

And when I delete .java, Intent gives an error

enter image description here

Note: My problem was not solved with Invalidate Caches / Restart... option in File

I don't know where the problem is. please help me.

CodePudding user response:

Kinda strange because it seems good to me. Try this.

Remove the lateinit and declare it directly when you need it, maybe it will solve the problem.

val intent = Intent(this, LauncherActivity::class.java)

I don't think the this@KotlinActivity is needed in this case.
Let me know if this fix it


UPDATE

Are you sure the findViewById<TextView>... is correct ? Shouldn't it has a declaration before ? Like

val view = findViewById<>...

CodePudding user response:

The solution is:

In build.gradle (:app) file, in dependencies, you should change appcompat version to 1.4.2.

befor error:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.5.0'
    ...
}

And when I changed the version to 1.4.2, the problem was solved

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.2'
    ...
}

And make sure the kotlin version is 1.5.0

  • Related