无法实例化活动|引起:kotlin.KotlinNullPointerException

时间:2017-09-04 17:34:36

标签: android kotlin

我收到此错误

  

致命的例外:主要                                                                                     过程:com.demo.gandharv.exkotlin,PID:7742                                                                                     java.lang.RuntimeException:无法实例化活动ComponentInfo {com.pantelwar.gandharv.scobokotlin / com.demo.gandharv.exkotlin.RegisterActivity}:kotlin.KotlinNullPointerException                                                                                         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3095)                                                                                         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)                                                                                         在android.app.ActivityThread.access $ 1100(ActivityThread.java:222)                                                                                         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1796)                                                                                         在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                         在android.os.Looper.loop(Looper.java:158)                                                                                         在android.app.ActivityThread.main(ActivityThread.java:7230)                                                                                         at java.lang.reflect.Method.invoke(Native Method)                                                                                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)                                                                                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)                                                                                      引起:kotlin.KotlinNullPointerException                                                                                         在com.demo.gandharv.exkotlin.RegisterActivity。(RegisterActivity.kt:12)                                                                                         at java.lang.Class.newInstance(Native Method)                                                                                         在android.app.Instrumentation.newActivity(Instrumentation.java:1096)                                                                                         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3085)                                                                                         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)                                                                                         在android.app.ActivityThread.access $ 1100(ActivityThread.java:222)                                                                                         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1796)                                                                                         在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                         在android.os.Looper.loop(Looper.java:158)                                                                                         在android.app.ActivityThread.main(ActivityThread.java:7230)                                                                                         at java.lang.reflect.Method.invoke(Native Method)                                                                                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)                                                                                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我在 AndroidMenifest.xml 中定义了 RegisterActivity

我不知道为什么我会收到此错误。

这是我的LoginActivity.kt

package com.demo.gandharv.exkotlin

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity : AppCompatActivity() {

var email: String = ""
var password: String = ""

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_login)

    loginButton.setOnClickListener {
        email = emailEditText.text.toString()
        password = passwordEditText.text.toString()
    }

    registerTextView.setOnClickListener {
        val intent = Intent(this@LoginActivity, RegisterActivity::class.java)
        startActivity(intent)
    }
}
}

0 个答案:

没有答案