java.lang.IllegalArgumentException:指定为非null的参数为null:方法kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull

我得到这个错误

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

为线路

override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent)

以下是整个代码。 这个代码最初是在java中,我使用Android Studio将其转换为Kotlin,但现在我得到这个错误。 我尝试重建和清理这个项目,但是这不起作用。

 val action = supportActionBar //get the actionbar action!!.setDisplayShowCustomEnabled(true) //enable it to display a custom view in the action bar. action.setCustomView(R.layout.search_bar)//add the custom view action.setDisplayShowTitleEnabled(false) //hide the title edtSearch = action.customView.findViewById(R.id.edtSearch) as EditText //the text editor //this is a listener to do a search when the user clicks on search button edtSearch?.setOnEditorActionListener(object : TextView.OnEditorActionListener { override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent): Boolean { if (actionId == EditorInfo.IME_ACTION_SEARCH) { Log.e("TAG","search button pressed") //doSearch() return true } return false } }) 

最后一个参数可以为null ,如文档所述 :

KeyEvent :如果通过回车键触发,这是事件; 否则,这是空的。

所以你需要做的是使Kotlintypes为空,否则注入的null检查会使应用程序崩溃,如果你已经看到一个null值的调用:

 edtSearch?.setOnEditorActionListener(object : TextView.OnEditorActionListener { override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent?): Boolean { ... } }) 

在这个答案中有关平台types的更多解释。