17

I got this error :

Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState

When i am trying to inflate a custom dialog in Kotlin , i got the error i wrote above on the super.onCreate line in the dialog.

the dialog code is :

class Custom_Dialog_Exit_App(var activity: Activity)// TODO Auto-generated constructor stub
    : Dialog(activity, R.style.full_screen_dialog) {

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.custom_dialog_exit_app)
        activity.window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT)

        initView()
    }

    fun initView() {
        initClicks()
    }

    fun initClicks() {


    }


}

and the init is :

val omer = Custom_Dialog_Exit_App(this@MainActivity)
        omer.show()

Please help

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
omer tamir
  • 314
  • 1
  • 3
  • 11

3 Answers3

36

override fun onCreate(savedInstanceState: Bundle) {

Since savedInstanceState can be null the type has to be Bundle?.

When you specify that a parameter is not null then kotlin generates a check in all cases. This includes when implementing a Java interface so you need to be careful about making nullable parameters non-null.

Kiskae
  • 24,655
  • 2
  • 77
  • 74
15

I also meet the error ,I changed the type Bundle to "Bundle?".Then it workd for me. In Kotlin you have to specify if the variable/parameter is null or not.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    init()
}
Umair
  • 6,366
  • 15
  • 42
  • 50
humanheima
  • 263
  • 3
  • 8
-3

change this line

  activity.window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT)

to

if(activity.window != null) { 
     activity.window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
               WindowManager.LayoutParams.MATCH_PARENT) 
} else {
     Log.e(TAG, "Window is null");
} 
Gil Goldzweig
  • 1,809
  • 1
  • 13
  • 26