Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unresolved reference 'Intent' : val intent = Intent

I am sure there is something obvious but have not been able to find a solution to this simple problem. The error is in a main activity attempting to start another activity when a user guesses the correct answer:

Error:(85, 23) Unresolved reference: Intent

The code is from the High/Low Android app in the book 'Kotlin Development for Android'.

val intent = Intent("com.example.user.highlow2.CorrectGuessActivity")
startActivity(intent)

The manifest has the following intent-filter for the called activity:

<intent-filter>
    <action android:name="com.example.user.highlow2.CorrectGuessActivity"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
like image 322
tomN Avatar asked Feb 19 '18 20:02

tomN


2 Answers

The original syntax and suggestions all yielded the same error. The MainActivity needs the following for the Intent to be recognized: import android.content.Intent

like image 104
tomN Avatar answered Nov 12 '22 06:11

tomN


Please keep it simple as possible use

val intent = Intent(this,CorrectGuessActivity::class.java)
startActivity(intent)
like image 43
Subtain Malik Avatar answered Nov 12 '22 04:11

Subtain Malik