[英]Android kotlin onCreate(savedInstanceState: Bundle?) cause IllegalArgumentException
The first Activity doesn't launch nevertheless Bundle?
第一个 Activity 没有启动
Bundle?
. .
class FirstActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bundle
引起:java.lang.IllegalArgumentException:参数指定为非空为空:方法kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull,参数包
This error should occur when override fun onCreate(savedInstanceState: Bundle)
当
override fun onCreate(savedInstanceState: Bundle)
时override fun onCreate(savedInstanceState: Bundle)
发生此错误
However, I fixed override fun onCreate(savedInstanceState: Bundle?)
但是,我修复了
override fun onCreate(savedInstanceState: Bundle?)
That's error occurred at Application class, not Activity.那是在应用程序类而不是活动中发生的错误。
Need to change Bundle into "Bundle?"需要将 Bundle 更改为“Bundle”? both Activity and Application class.
Activity 和 Application 类。
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
}
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?) {}
I had same error when i exchange .java to .kt automatically.当我自动将 .java 交换为 .kt 时,我遇到了同样的错误。 But the real wrong point wasn't in Activity.
但真正的错误点不在 Activity 中。 In my case, the wrong place was ActivityLifecycleCallbacks where some parameters missing '?'
就我而言,错误的地方是 ActivityLifecycleCallbacks,其中某些参数缺少 '?' in exchanging.
在交换。
Wrong:错误:
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle)
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle)
Correct:正确:
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?)
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.