当前位置: 首页 > 知识库问答 >
问题:

IllegalArgumentException:指定为Non-Null的savedInstanceState为Null

翟冯浩
2023-03-14

当我启动mainactivity时,遇到一个奇怪的错误:

06-16 16:01:05.193 2083-2083/? E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.android.example.github, PID: 2083
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.github/com.android.example.github.ui.MainActivity}: 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:2666)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
            at android.app.ActivityThread.-wrap12(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:154)
            at android.app.ActivityThread.main(ActivityThread.java:6121)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
          Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
            at com.android.example.github.injection.AppInjector$init$1.onActivityCreated(AppInjector.kt)
            at android.app.Application.dispatchActivityCreated(Application.java:197)
            at android.app.Activity.onCreate(Activity.java:961)
            at android.support.v4.app.BaseFragmentActivityGingerbread.onCreate(BaseFragmentActivityGingerbread.java:54)
            at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:319)
            at com.android.example.github.ui.MainActivity.onCreate(MainActivity.kt:20)
            at android.app.Activity.performCreate(Activity.java:6682)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:154) 
            at android.app.ActivityThread.main(ActivityThread.java:6121) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 

这是我的MainActivity类:

class MainActivity : LifecycleActivity(), HasSupportFragmentInjector {

    lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
        @Inject set

    lateinit var navigationController: NavigationController

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

        if (savedInstanceState == null) {
            navigationController.navigateToSearch()
        }
    }

    override fun supportFragmentInjector(): AndroidInjector<Fragment> {
        return dispatchingAndroidInjector
    }

}

当参数savedinstanceState被指定为非空时,该错误指出它为空;但它是可为null的(savedInstanceState:bundle?),并且onCreate()方法在源代码中标记为@nullable

我在其他Kotlin项目中没有遇到过这个错误。我使用的是Kotlin版本1.1.2-5;与1.1.2-3有相同的误差。

共有1个答案

双元魁
2023-03-14

问题似乎不在oncreate方法中。尝试查看com.android.example.github.injection.AppInjector$init$1.OnActivityCreated(AppInjector.kt)。我无法判断它是否是生成的类,但它应该会给您一个下一步要做什么的想法。

 类似资料: