Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crash caused by data binding related to java.lang.Runnable android.databinding.ViewDataBinding.mRebindRunnable

The exception is the following:

java.lang.NullPointerException: Attempt to read from field 'java.lang.Runnable android.databinding.ViewDataBinding.mRebindRunnable' on a null object reference
        at android.databinding.ViewDataBinding.access$100(ViewDataBinding.java:51)
        at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:142)
        at android.view.View.dispatchAttachedToWindow(View.java:14525)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2836)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1364)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
        at android.view.Choreographer.doFrame(Choreographer.java:606)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Let me try my best to make the description brief and clear.

First, this is related to a layout added dynamically. The activity's data binding works perfectly without any problem. Here is the layout foo_view:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="foo"
            type="net.mydomain.myapp.MyActivity.Foo" />
        <import type="android.view.View" />
    </data>
    <!--For the sake of debugging, no data binding is actually used-->
    ...
</layout>

In MyActivity.java:

public class MyActivity extends AppCompatActivity {
    public class Foo{
       ...
    }


   ...
   addFoo(){
       FooViewBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.foo_view, myGridLayout, true); 
       Foo foo = new Foo();
       binding.setFoo(foo);  
   }
}

The app cashes immediately upon the start of MyActivity. The crash is not caused by a specific line of code.

Could anyone shed some light on this?

[Edit] 2016-06-30

The crash happens on a Lollipop, but same code works fine on a Jelly Bean

like image 407
Hong Avatar asked Jan 27 '26 20:01

Hong


1 Answers

Just in case someone has the same problem, this errors occurs when you change the tag (i.e. view.setTag(object)) of a data-binding enabled view, as the data binding library uses the tag for itself.

like image 146
Alex O. Avatar answered Jan 30 '26 21:01

Alex O.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!