Kotlin自定义对话框参数指定为非空 [英] Kotlin custom dialog Parameter specified as non-null

查看:224
本文介绍了Kotlin自定义对话框参数指定为非空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

由于:java.lang.IllegalArgumentException:参数指定为 非null为null:方法 kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull,参数 savedInstanceState

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

当我试图在Kotlin中膨胀自定义对话框时 ,我在对话框中的super.onCreate行上收到了上面写的错误.

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.

对话框代码为:

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() {


    }


}

的初始化是:

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

请帮助

推荐答案

override fun onCreate(savedInstanceState: Bundle) {

由于savedInstanceState可以为null,因此类型必须为Bundle?.

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

当您指定参数不为null时,kotlin会在所有情况下生成检查.这包括在实现Java接口时的内容,因此您在将可为空的参数设置为非空时需要格外小心.

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.

这篇关于Kotlin自定义对话框参数指定为非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆