Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio & Kotlin: unresolved reference:context

Tags:

android

kotlin

I've tried hundreds of ways to resolve this reference problem:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(toolbar)

        val dm = DataManager()
        val adapterCourses = ArrayAdapter<CourseInfo>(context:  this,
                    android.R.layout)

but in ArrayAdapter<CourseInfo>(context: this, android.R.layout) I get unresolved reference: context and I have no idea why.

Android Studio version: 3.3.2 Kotlin version: 1.3.21

Could anyone help me?

like image 579
Rybecki Avatar asked Jul 31 '26 10:07

Rybecki


1 Answers

I had a similar error message because I didn't import the Context. If you haven't explicitly imported Context, try adding this to your import list near the start of your Activity file:

 import android.content.Context          
like image 143
V Chapman Avatar answered Aug 03 '26 01:08

V Chapman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!