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

    btnLogin.setOnClickLister {
        val intent = Intent(this, homemenu::class.java)
        startActivity(intent)
    }
} }

The Photo of the code

I have set the button for the Intent function. But it is still an error how can I fix this. The task I just only want the button after click it will head to another activity. appreciate for helping

Ricky Mo
  • 6,285
  • 1
  • 14
  • 30
  • The error message explains itself. Where did you get `btnLogin`? It is not defined. – Ricky Mo Jan 24 '22 at 05:08
  • You need to use [findViewById()](https://developer.android.com/reference/android/app/Activity#findViewById(int)) or [view binding](https://developer.android.com/topic/libraries/view-binding) – Ricky Mo Jan 24 '22 at 05:10

1 Answers1

0

It is because btnLogin is not defined.

You should define btnLogin (from activity_main xml)

val btnLogin = findViewById(R.id.btnLogin) as Button

Rest is good.

KpStar
  • 122
  • 7