Reputation: 238
Im trying to set Intent
in Kotlin in Android Studio to launch another Activity.kt
:
val i : Intent = Intent(this, MainActivity::class.java)
Android Studio shows me an error, and it doesnt compile:
Error:(23, 26) None of the following functions can be called with the arguments supplied:
public constructor Intent(p0: Context!, p1: Class<*>!) defined in android.content.Intent
public constructor Intent(p0: String!, p1: Uri!) defined in android.content.Intent
I think syntax is correct, so what is wrong?
Upvotes: 3
Views: 9062
Reputation: 1390
You should use package context as follows:
val intent = Intent(this@LoginActivity,MainActivity::class.java)
startActivity(intent)
Thank you.
Upvotes: 2
Reputation: 301
You should write like this:
val i : Intent by lazy { Intent(this, MainActivity::class.java) }
Upvotes: -1