刚才遇到一个Bug,是使用Kotlin时产生的,先看一下报错信息:
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method
kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
at com.ckw.lightweightmusicplayer.ui.localsongs.LocalSongsActivity.initView(LocalSongsActivity.kt)
at com.ckw.lightweightmusicplayer.base.BaseActivity.onCreate(BaseActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6357)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2515)
at android.app.ActivityThread.access$1000(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5571)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
关键信息在这里:
Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
说的是savedInstanceState这个参数在原来的代码中被设定是不能为空的,但是现在传入的是空的。
通过检查发现在这里:
override fun initView(savedInstanceState: Bundle) {
}
一般初始化的时候,savedInstanceState都是空的,所以需要改成如下:
override fun initView(savedInstanceState: Bundle?) {
}
加了个问号,设置savedInstanceState为可空就好了
版权声明:本文为ckwccc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。