title: Unable to bind custom adapter to layouts with include tag
body: <p>I am trying to use Kotlin's Sealed class for handling states in my app. I have seperated different states in different layout files for reusing them. But the problem is that even though I am able to using it in a fragment successfully it is not working in another fragment. Log is very confusing for this error. Maybe there is a subtle error which I am not able to find in my code.</p>
  <p>This is my sealed class which is used for state handling :</p>
  <pre class="lang-kotlin prettyprint-override"><code>sealed class LoadStates {
      object Loading : LoadStates()
      class Error(val msg: String = &quot;Something went wrong&quot;) : LoadStates()
      class Empty(val msg: String = &quot;No item&quot;) : LoadStates()
      object NotEmpty : LoadStates()
  
      companion object {
          fun &lt;T&gt; decideEmptyOrNot(list: List&lt;T&gt;?,msg: String): LoadStates {
              return if (list.isNullOrEmpty()) { Empty(msg) } else { NotEmpty }
          }
      }
  }
  </code></pre>
  <p>There are the custom binding adapter that I am using :</p>
  <pre class="lang-kotlin prettyprint-override"><code>@BindingAdapter(&quot;bindLoadingState&quot;)
  fun uiStateWhileLoading(view: View, state: LoadStates) {
      view.visibility = if (state is LoadStates.Loading) { View.VISIBLE } else { View.GONE }
  }
  
  @BindingAdapter(&quot;bindErrorState&quot;)
  fun uiStateWhenError(view: LinearLayout, state: LoadStates) {
      view.visibility = if(state is LoadStates.Error) {
          val msg = view.getChildAt(1) as TextView
          msg.text = state.msg
          View.VISIBLE
      } else { View.GONE }
  }
  
  @BindingAdapter(&quot;bindEmptyState&quot;)
  fun uiStateWhenEmpty(view: LinearLayout, state: LoadStates) {
      if(state is LoadStates.Empty) {
          val msg = view.getChildAt(1) as TextView
          msg.text = state.msg
          view.visibility = View.VISIBLE
      } else {
          view.visibility = View.GONE
      }
  }
  
  @BindingAdapter(&quot;bindNonEmptyState&quot;)
  fun uiStateWhenNotEmpty(view: View, state: LoadStates) {
      view.visibility = if (state is LoadStates.NotEmpty) { View.VISIBLE } else { View.INVISIBLE }
  }
  
  @BindingAdapter(&quot;bindDisableState&quot;)
  fun bindButtonDisableState(view: View, state: LoadStates) {
      view.isEnabled = state !is LoadStates.Loading
  }
  </code></pre>
  <p>XML code of my layout file :</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
  
      &lt;data&gt;
          &lt;variable
              name=&quot;presenter&quot;
              type=&quot;bd.edu.daffodilvarsity.classmanager.features.admin.bookedrooms.rangeddate.BookedRoomsRangedDate&quot; /&gt;
          &lt;variable
              name=&quot;viewModel&quot;
              type=&quot;bd.edu.daffodilvarsity.classmanager.features.admin.bookedrooms.common.BookedRoomsAdminViewModel&quot; /&gt;
      &lt;/data&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          tools:context=&quot;.features.admin.bookedrooms.rangeddate.BookedRoomsRangedDate&quot;&gt;
  
          ...
          ......
          ............
  
          &lt;include
              layout=&quot;@layout/state_empty&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;0dp&quot;
              app:state=&quot;@{viewModel.uiStates}&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@id/top_view&quot;/&gt;
  
          &lt;include
              layout=&quot;@layout/state_loading&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;0dp&quot;
              app:bindLoadingState=&quot;@{viewModel.uiStates}&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@id/top_view&quot; /&gt;
  
          &lt;include
              layout=&quot;@layout/state_error&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;0dp&quot;
              app:state=&quot;@{viewModel.uiStates}&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@id/top_view&quot;/&gt;
  
          &lt;androidx.recyclerview.widget.RecyclerView
              android:id=&quot;@+id/recycler_view&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;0dp&quot;
              app:bindNonEmptyState=&quot;@{viewModel.uiStates}&quot;
              app:layoutManager=&quot;androidx.recyclerview.widget.LinearLayoutManager&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@id/top_view&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;/&gt;
  
          &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_margin=&quot;18dp&quot;
              android:onClick=&quot;@{() -&gt; presenter.fetchBookedRooms()}&quot;
              android:src=&quot;@drawable/ic_search&quot;
              app:bindDisableState=&quot;@{viewModel.uiStates}&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;/&gt;
  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  &lt;/layout&gt;
  
  </code></pre>
  <p>XML files of my 3 states :</p>
  <p>state_loading : <a href="https://pastebin.com/AhwvV69P" rel="nofollow noreferrer">https://pastebin.com/AhwvV69P</a></p>
  <p>state_error : <a href="https://pastebin.com/TnfynHNi" rel="nofollow noreferrer">https://pastebin.com/TnfynHNi</a></p>
  <p>state_empty : <a href="https://pastebin.com/xLeQQ1GX" rel="nofollow noreferrer">https://pastebin.com/xLeQQ1GX</a></p>
  <p>I am pretty sure my ui state livedata is not null. Here is the Crash Log :</p>
  <pre><code>2020-08-10 17:34:14.837 15167-15167/bd.edu.daffodilvarsity.classmanager E/AndroidRuntime: FATAL EXCEPTION: main
      Process: bd.edu.daffodilvarsity.classmanager, PID: 15167
      java.lang.RuntimeException: Failed to call observer method
          at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:226)
          at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
          at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
          at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
          at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
          at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
          at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
          at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
          at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
          at androidx.fragment.app.FragmentViewLifecycleOwner.handleLifecycleEvent(FragmentViewLifecycleOwner.java:51)
          at androidx.fragment.app.Fragment.performStart(Fragment.java:2737)
          at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:365)
          at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1194)
          at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
          at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
          at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
          at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
          at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7356)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:915)
       Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter state
          at bd.edu.daffodilvarsity.classmanager.common.adapter.CustomBindingAdaptersKt.uiStateWhileLoading(Unknown Source:7)
          at bd.edu.daffodilvarsity.classmanager.databinding.FragmentBookedRoomsRangedDateBindingImpl.executeBindings(FragmentBookedRoomsRangedDateBindingImpl.java:206)
          at androidx.databinding.ViewDataBinding.executeBindingsInternal(ViewDataBinding.java:473)
          at androidx.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:445)
          at androidx.databinding.ViewDataBinding$OnStartListener.onStart(ViewDataBinding.java:1687)
          at java.lang.reflect.Method.invoke(Native Method)
          at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:216)
          at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194) 
          at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185) 
          at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37) 
          at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361) 
          at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300) 
          at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339) 
          at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145) 
          at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131) 
          at androidx.fragment.app.FragmentViewLifecycleOwner.handleLifecycleEvent(FragmentViewLifecycleOwner.java:51) 
          at androidx.fragment.app.Fragment.performStart(Fragment.java:2737) 
          at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:365) 
          at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1194) 
          at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224) 
          at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997) 
          at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953) 
          at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849) 
          at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413) 
          at android.os.Handler.handleCallback(Handler.java:883) 
          at android.os.Handler.dispatchMessage(Handler.java:100) 
          at android.os.Looper.loop(Looper.java:214) 
          at android.app.ActivityThread.main(ActivityThread.java:7356) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:915) 
  </code></pre>