# Kotlin app crashes when switching activity

**URL:** <https://discuss.kotlinlang.org/t/kotlin-app-crashes-when-switching-activity/25855>\
**Category:** Android\
**Created:** [October 23, 2022, 8:29am UTC](https://discuss.kotlinlang.org/t/kotlin-app-crashes-when-switching-activity/25855 "2022-10-23T08:29:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kasmorioffi](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@Kasmorioffi](https://discuss.kotlinlang.org/u/Kasmorioffi)\
**Post date:** [October 23, 2022, 8:29am UTC](https://discuss.kotlinlang.org/t/kotlin-app-crashes-when-switching-activity/25855/1 "2022-10-23T08:29:09Z")

</div>

Hello, i have a problem with switching activitys in my app. I made a button that switches the activitys but everytime i press the button my app crashes. Android studio also gave me a few error codes. I have these in a screenshot and also the code for the activity switch. Would be great if someone could help.

```auto
   override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val MainActivity2 = findViewById<Button>(R.id.button)
        MainActivity2.setOnClickListener {
            val Intent = Intent(this,MainActivity2::class.java)
            startActivity(Intent)
        }

```

 ![Screenshot 2022-10-22 175216](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/b/bbdd9acf277e65ef9a383662aa22ac0fda9ec53d.png)
