One of the coolest features of Android data binding support is that it also creates presentation fields with set identifiers. This simplifies the codebase since no fields or calls to findViewById()
are needed.
But the problem is that a binding instance can only be obtained through a call to bind()
, which tends to schedule the binding. This is bad when data is received asynchronously and a NullPointerException
usually NullPointerException
.
Is it possible to get a binding instance with View fields minus the actual data binding process?
Stack trace:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference at com.app.android.databinding.ActivityRestaurantDetailsBinding.executeBindings(ActivityRestaurantDetailsBinding.java:381) at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:350) at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:167) at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:137) at android.view.View.dispatchAttachedToWindow(View.java:14525)
source share