kamilp
kamilp

Reputation: 238

Kotlin Intent syntax error

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

Answers (3)

Ishwor Khanal
Ishwor Khanal

Reputation: 1390

You should use package context as follows:

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

Thank you.

Upvotes: 2

kamilp
kamilp

Reputation: 238

val i = Intent(this@MainActivity, Activity::class.java)

Upvotes: 15

Constantin Chernishov
Constantin Chernishov

Reputation: 301

You should write like this: val i : Intent by lazy { Intent(this, MainActivity::class.java) }

Upvotes: -1

Related Questions