Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.5K
Visualizações
Android Studio & Kotlin: unresolved reference:context

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?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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          
over 4 years ago · Santiago Trujillo Relatório

0

The column in Kotlin is used for some things, but not when passing named arguments. The syntax for passing a named parameter is parameterName = parameterValue.

When you write context = this, while passing a parameter, you are simply referring to the parameter context of the function you are calling, explicitly saying that this has to correspond to that context parameter. This is not very useful in this case unless you want to be very explicit.

The usefulness of using named arguments arise when you are dealing with optional parameters or when you are passing the parameters out of order.
E.g.

// DECLARATION of function abc
fun abc(s: String = "", i: Int = 0)

// USAGE of function abc passing only an Int
abc(i = 314)

The function abc has two parameters and they have a default value. In this case, you can avoid passing any parameter if you are fine with the defaults. But if you only want to pass i, you can do it by specifying its name, as done in the example.

Similarly, you can choose to pass parameters out of order, in that case, you'll do:

abc(i = 314, s = "something")
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda