Home > Net >  I get an error for this Intent , I dont know why
I get an error for this Intent , I dont know why

Time:03-21

I have created a 50 second timer. I want it to call another screen using an Intent after the timer ends. But I get an error saying

None of the following functions can be called with the arguments supplied. (Context!, Class<*>!) defined in android.content.Intent (String!, Uri!) defined in android.content.Intent

class NewGame : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_new_game)
    val results = findViewById<TextView>(R.id.textView5)
    val results2 = findViewById<TextView>(R.id.textView6)
    val greater = findViewById<Button>(R.id.button3)
    val equal = findViewById<Button>(R.id.button4)
    val less = findViewById<Button>(R.id.button5)
    val result = findViewById<TextView>(R.id.textView7)
    val submit = findViewById<Button>(R.id.button7)
    val counttime = findViewById<TextView>(R.id.textView8)
    var great = ""
    var equ = false
    var les = false
    var hasSubmitted = false
    var answer = 0
    var counter = 0


    gameplay(results, results2, result, greater, equal, less)
    

    val timer = object: CountDownTimer(50000, 1000) {
        override fun onTick(millisUntilFinished: Long) {
            counttime.setText((counter).toString());
            counter  ;
        }

        override fun onFinish() {
            val endGameIntent = Intent(this, EndGame::java)
            startActivity(endGameIntent)
        }

        
    }
    timer.start()
}

CodePudding user response:

You pass context to the Intent and in your case this in that scope refers to CountDownTimer.

val endGameIntent = Intent(this@NewGame , EndGame::java)
  • Related