Kotlin custom dialog Parameter specified as non-null

可紊 提交于 2019-12-01 15:13:54

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.

humanheima

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

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");
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!