LoginSignup
1
0

More than 3 years have passed since last update.

BindingAdapterで「Caused by: java.lang.IllegalStateException: Required DataBindingComponent is null」

Posted at

DataBindingでBindingAdapterを使っていると、以下のエラーが発生することがあります。

Caused by: java.lang.IllegalStateException: Required DataBindingComponent is null in class ActivityMainBindingImpl. 
A BindingAdapter in com.example.sample.BindingAdapter is not static and requires an object to use, retrieved from the DataBindingComponent. 
If you don't use an inflation method taking a DataBindingComponent, use DataBindingUtil.setDefaultComponent or make all BindingAdapter methods static.

これは@JvmStaticがないことによるエラーなので、BindingAdapterに追加すると解決します。

object BindingAdapter {

    @BindingAdapter("method")
    // 追加
    @JvmStatic
    fun TextView.method(text: String) {
        this.text = text
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0