当我单击忘记密码应用程序崩溃时

发布于 2025-02-03 03:16:41 字数 720 浏览 2 评论 0原文

这是代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2025-02-10 03:16:41

从我可以从日志中看到的内容,您在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 a var variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文