Kotlin Android start new Activity

后端 未结 17 2304
不知归路
不知归路 2020-12-07 23:33

I want to start another activity on Android but I get this error:

Please specify constructor invocation; classifier \'Page2\' does not have a companio

17条回答
  •  青春惊慌失措
    2020-12-08 00:28

    This is because your Page2 class doesn't have a companion object which is similar to static in Java so to use your class. To pass your class as an argument to Intent, you will have to do something like this

    val changePage = Intent(this, Page2::class.java)
    

提交回复
热议问题