gpt4 book ai didi

android-databinding - java.lang.Runnable android.databinding.ViewDataBinding.mRebindRunnable相关数据绑定(bind)导致的App崩溃

转载 作者:行者123 更新时间:2023-12-04 04:10:22 28 4
gpt4 key购买 nike

异常(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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com