onCreate从Java转换到Kotlin后崩溃

我将我的Launcher Activity从Java转换为Kotlin,并且在onCreate()中崩溃,我不明白它为什么会崩溃。

Java的:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 

科特林:

 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) 

调用堆栈:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc/com.abcAuthentication.AuthenticationActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState at com.abcActivity.AppLifecycleTracker.onActivityCreated(AppLifecycleTracker.kt) at android.app.Application.dispatchActivityCreated(Application.java:195) at android.app.Activity.onCreate(Activity.java:922) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:277) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85) at com.abcAuthentication.AuthenticationActivity.onCreate(AuthenticationActivity.kt:147) at android.app.Activity.performCreate(Activity.java:6251) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

    One Solution collect form web for “onCreate从Java转换到Kotlin后崩溃”

    看起来像AppLifecycleTracker中的savedInstanceState: Bundle方法有一个参数savedInstanceState: Bundle ,应该是savedInstanceState: Bundle? ,因为在创建活动时不一定有保存的状态,这意味着参数值可以为null 。 Kotlin检查这个以确保无效的安全 。

    崩溃似乎与活动本身的转换无关。

    Kotlin language will be the best programming language for Android.