无法生成视图绑定程序java.lang.StackOverflowError

尝试将应用程序从支持迁移到androidx for android29。在android studio中出现错误无法生成视图绑定java.lang.StackOverflowError 。不显示任何文件名或行号时出错。

在研究了可能的解决方案之后,我发现此问题与绑定适配器有关。

在迁移应用程序时,一段代码由android studio自动转换。

旧代码

android:visibility="@{rating.isExtended.get()?View.VISIBLE:View.GONE}"

新代码

android:visibility="@{safeUnbox(rating.isExtended.get())?View.VISIBLE:View.GONE}"

我关注了this链接,并使用了以下代码段。

@BindingAdapter("app:goneUnless")
public static void goneUnless(View view,Boolean visible) {
    view.visibility = visible ? View.VISIBLE : View.GONE;
}

现在问题已解决。

buxianwangluo 回答:无法生成视图绑定程序java.lang.StackOverflowError

该错误是由于getValue()中存在get()layout xml file

enter image description here

在我的layout.xml文件之一中,我写了mutableLiveDataVariable.getValue(),这是错误的做法。当我的Studio版本为3.5.1时,它可以正常工作,没有任何错误。

我将其更新为3.5.3。我开始得到cannot generate view binders java.lang.StackOverflowError。所以我删除了getValue()并将代码更改为 android:text="@={viewModel.firstName}"

它奏效了。

请检查下面的报告链接。

https://issuetracker.google.com/issues/143778134

https://issuetracker.google.com/issues/144604674

本文链接:https://www.f2er.com/3145108.html

大家都在问