当我单击忘记密码应用程序崩溃时
这是代码:
class MainActivity : AppCompatActivity() {
lateinit var txtForgotPassword: TextView
lateinit var register: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
txtForgotPassword = findViewById(R.id.frgtpass)
txtForgotPassword.setOnClickListener {
val intent=Intent(this@MainActivity,Register::class.java)
startActivity(intent)
}
}
}
这是我遇到的错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vishesh.foodrunner/com.vishesh.foodrunner.Register}: java.lang.NullPointerException
This is the code:
class MainActivity : AppCompatActivity() {
lateinit var txtForgotPassword: TextView
lateinit var register: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
txtForgotPassword = findViewById(R.id.frgtpass)
txtForgotPassword.setOnClickListener {
val intent=Intent(this@MainActivity,Register::class.java)
startActivity(intent)
}
}
}
This is the error I faced:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vishesh.foodrunner/com.vishesh.foodrunner.Register}: java.lang.NullPointerException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我可以从日志中看到的内容,您在MainActivity第17行中拥有一个属性,您分配了
LateInit
属性,但忘记了初始化它。我不确定您是否使用过它,但是为其提供基本值,并且错误会消失,您可以随时更改,因为它是var
variable。From what I can see from the logs you have a property in MainActivity line 17 which you assigned
lateinit
property but forgot to initialize it. I am not sure if you used it or not but give a base value to it and the error will go away you can always change as it is avar
variable.