I can't call my button, it gives me error "Unresolved Reference"

Viewed 574

So my problem is, when I try to call my button it doesn't work and gives me an error saying "Unresolved Reference":

Calling the button: enter image description here

Button on XML: enter image description here

1 Answers

Initialize your button in the Kotlin file, MainActivity.kt or whatever you named it.

Button btn_start = (Button) findViewById(R.id.btn_start);
btn_start.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick (View v) {

    }
});

This is in Java because I don't know Kotlin, but hopefully it's easy to translate.

Also note: you can add codeblocks in your question. Please do so as it makes it convenient for everyone.

Related