由与java.lang.Runnable相关的数据绑定导致的应用程序崩溃android.databinding.ViewDataBinding.mRebindRunnable [英] App crash caused by data binding related to java.lang.Runnable android.databinding.ViewDataBinding.mRebindRunnable
问题描述
例外情况如下:
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.
首先,这与动态添加的布局有关.活动的数据绑定可以完美地工作,没有任何问题.这是布局foo_view:
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>
在MyActivity.java中:
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);
}
}
该应用程序在MyActivity启动后立即兑现.崩溃不是由特定的代码行引起的.
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?
2016-06-30
崩溃发生在棒棒糖上,但是相同的代码在果冻豆上也能正常工作
The crash happens on a Lollipop, but same code works fine on a Jelly Bean
推荐答案
即使有人遇到相同的问题,更改标签(即 view.setTag(object)
)时也会发生此错误启用了数据绑定的视图,因为数据绑定库本身使用标记.
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.
这篇关于由与java.lang.Runnable相关的数据绑定导致的应用程序崩溃android.databinding.ViewDataBinding.mRebindRunnable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!