2017-12-16 4 views
2

は私がラインjava.lang.IllegalArgumentExceptionが非ヌルとして指定されたパラメータが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 
    } 
}) 

答えて

3

docsによって記載されるように、最後のパラメータは、nullすることができる:

KeyEvent:キー入力によってトリガ場合、これはイベントです。それ以外の場合はnullです。

だから何あなたがしなければならないことは、あなたはすでにそれを見てきたとして、それがnull値とのコールを取得するときにそうでない場合は注入さnullチェックは、アプリケーションがクラッシュします、これを説明するにはKotlinタイプがNULL可能にする次のとおりです。

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

プラットフォームタイプの詳細はthis answerです。

関連する問題