异常(exception)情况如下:

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)

让我尽量使描述简洁明了。

首先,这与动态添加的布局有关。事件的数据绑定(bind)完美无缺。
这是布局 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>

在 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);
   }
}

该应用程序在 MyActivity 启动后立即兑现。崩溃不是由特定的代码行引起的。

任何人都可以对此有所了解吗?

[编辑] 2016-06-30

崩溃发生在 Lollipop 上,但相同的代码在 Jelly Bean 上运行良好

最佳答案

万一有人遇到同样的问题,当您更改启用数据绑定(bind)的 View 的标记(即 view.setTag(object) )时会发生此错误,因为数据绑定(bind)库将标记用于自身。

关于android-databinding - java.lang.Runnable android.databinding.ViewDataBinding.mRebindRunnable相关数据绑定(bind)导致App崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37374303/

10-12 02:01