无法实例化活动| 引起:kotlin.KotlinNullPointerException
我得到这个错误
致命例外:主进程:com.demo.gandharv.exkotlin,PID:7742 java.lang.RuntimeException:无法实例化活动ComponentInfo {com.pantelwar.gandharv.scobokotlin / com.demo.gandharv.exkotlin.RegisterActivity}:kotlin。在android.app.ActivityThread.access $ 1100(ActivityThread.java:222)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3095)上的KotlinNullPointerException。在android.app.ActivityThread的android.os.Looper.loop(Looper.java:158)上的android.os.Handler.dispatchMessage(Handler.java:102)app.ActivityThread $ H.handleMessage(ActivityThread.java:1796) .main(ActivityThread.java:7230)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)at com.android.internal java.lang.reflect.Method.invoke(Native Method) .os.ZygoteInit.main(ZygoteInit.java:1120)由com.demo.gandharv.exkotlin.RegisterActivit引起的:kotlin.KotlinNullPointerException y。(RegisterActivity.kt:12)at android.app.Instrumentation.newActivity(Instrumentation.java:1096)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3085)at java.lang.Class.newInstance(Native Method) )at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)at android.app.ActivityThread.access $ 1100(ActivityThread.java:222)at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1796)at android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:158)at android.app.ActivityThread.main(ActivityThread.java:7230)at java.lang.reflect .Method.invoke(Native Method)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)at 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) } } }