skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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<>...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search