Home » Android » Android kotlin onCreate(savedInstanceState: Bundle?) cause IllegalArgumentException

Android kotlin onCreate(savedInstanceState: Bundle?) cause IllegalArgumentException

Posted by: admin November 1, 2017 Leave a comment

Questions:

The first Activity doesn’t launch nevertheless 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

This error should occur when override fun onCreate(savedInstanceState: Bundle)

However, I fixed override fun onCreate(savedInstanceState: Bundle?)

Answers:

That’s error occurred at Application class, not Activity.

Need to change Bundle into “Bundle?” both Activity and Application class.

  override fun onActivityCreated(activity: Activity, bundle: Bundle?) {

    }

  override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?) {}