Unresolved reference: Question

So I have been following the book word for word on page 46 it tells me that I should run the GeoQuiz and that it should show the 1st question but I’m getting an Unresolved reference: Question. I don’t know if anybody got this and how did you fix it.

1 Like

I’d like to see more of the actual error to help you, but the problem of an Unresolved reference means that the compiler doesn’t know about the Question variable. It means it doesn’t think it is defined somewhere. Can you show the code you have where you first use the Question variable? Also show the error – or look at it more closely because it will tell you the line number of the code where this error occurred. Then we can go to that line and determine more about why the error occurred. :slight_smile:

code

package com.bignerdranch.android.geoquiz

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.TextView
import android.widget.Toast

class MainActivity : AppCompatActivity() {
private lateinit var trueButton: Button
private lateinit var falseButton: Button
private lateinit var nextButton: Button
private lateinit var questionTextView: TextView

private val questionBank = listOf(
        Question(R.string.question_australia, true),
        Question(R.string.question_oceans, true),
        Question(R.string.question_mideast, false),
        Question(R.string.question_africa, false),
        Question(R.string.question_americas, true),
        Question(R.string.question_asia, true))

private var currentIndex = 0

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

    trueButton = findViewById(R.id.true_button)
    falseButton = findViewById(R.id.false_button)
    nextButton = findViewById(R.id.next_button)
    questionTextView = findViewById(R.id.question_text_view)

    trueButton.setOnClickListener{ view: View ->
        Toast.makeText(
                this,
                R.string.correct_toast,
                Toast.LENGTH_SHORT)
                .run { this.setGravity(Gravity.TOP,0,0)
                    this.show() }

    }
    falseButton.setOnClickListener { view: View ->
        Toast.makeText(
                this,
                R.string.incorrect_toast,
                Toast.LENGTH_SHORT).run { this.setGravity(Gravity.TOP,0,0)
            this.show() }


    }
    val questionTextResId = questionBank[currentIndex].textResId
    questionTextView.setText(questionTextResId)

}

}

this is the error I get
e:/Users/username/Android_Studio/GioQuiz/app/src/main/java/com/bignerdranch/android/geoquiz/MainActivity.kt: (18, 13): Unresolved reference: Question

thank you so much for the help new to posting so I don’t know if I did everything correctly

So I figured out what I did wrong when I made the question class I made it in the incorrect place so it was never using Questions

1 Like