user9068821
user9068821

Reputation:

Intent in Kotlin

Why can't I just write class.kotlin instead of writing class.java. Because AndroidMeActivity is a kotlin class and I am getting an error ("Unsoloved refrence: java") when I write this,

How can I fix it.

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

Upvotes: 2

Views: 2116

Answers (4)

Aftab Alam
Aftab Alam

Reputation: 2049

You can use intent like this.

val button = findViewById<Button>(R.id.btn_login);
button.setOnClickListener{
    val intent = Intent(this, OTPActivity::class.java)
    startActivity(intent)
}

Upvotes: 0

user4571931
user4571931

Reputation:

if your AndroidMeActivity class is java class then used below code ..

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

if you are used android studio 3.0 above then is working if below then you can add kotlin plugins in android studio and setup configratution.

i suggest you can update your android studio 3.0 above is automatically supported kotlin. then after any new project start it provide include kotlin option in dialog where define you app name.

Upvotes: 0

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

"Unsoloved refrence: java"

Read Reflection

Reflection is a set of language and library features that allows for introspecting the structure of your own program at runtime.

Make sure, You added org.jetbrains.kotlin:kotlin-gradle-plugin

buildscript {
    ext.kotlin_version = '1.2.30'
    ext.gradle_version = '3.0.1'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

And check you added below in your module level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

Upvotes: 1

matin sayyad
matin sayyad

Reputation: 585

On the Java platform, the runtime component required for using the reflection features is distributed as a separate JAR file (kotlin-reflect.jar). This is done to reduce the required size of the runtime library for applications that do not use reflection features. If you do use reflection, please make sure that the .jar file is added to the classpath of your project.

see link https://kotlinlang.org/docs/reference/reflection.html#class-references

Upvotes: 0

Related Questions