“由...引起的:java.lang.RuntimeException:视图必须具有标签"的实际含义是什么? [英] What the actual meaning `Caused by: java.lang.RuntimeException: view must have a tag`?

查看:160
本文介绍了“由...引起的:java.lang.RuntimeException:视图必须具有标签"的实际含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果知道想要什么标签,请通知我.

Please inform me if knowing whats tag that wanted.

Caused by: java.lang.RuntimeException: view must have a tag

__ BaseActivity.java

__BaseActivity.java

    @Override
    public void setContentView(int layoutResID) {

        mBinding.contentParent.removeAllViews();
        DataBindingUtil.inflate(LayoutInflater.from(this), layoutResID, mBinding.contentParent, true);
        super.setContentView(mBinding.getRoot());
    }

__ ChildActivity.java

__ChildActivity.java

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.my_wallet);
}

错误logcat

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mydev}: java.lang.RuntimeException: view must have a tag
        at <more...>
     Caused by: java.lang.RuntimeException: view must have a tag
        at android.databinding.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:121)

推荐答案

通常在尝试使用DataBindingUtil.inflate()来填充不支持数据绑定的布局时会发生这种情况.换句话说,您要膨胀的布局的根元素没有为<layout>.

This usually happens when attempting to use DataBindingUtil.inflate() to inflate a layout that does not support data binding. In other words, the layout you're attempting to inflate does not have its root element as <layout>.

在重构 Activity 以使用数据绑定时,我遇到了这个问题,并且 Activity 具有多种布局.我成功地重构了其中的一种布局,在其根部包含了<layout>元素,但是我没有重构所有其他布局的 all (其他屏幕密度,语言,模块等的布局).

I have run into this problem when refactoring an Activity to use data binding, and the Activity has multiple layouts. I successfully refactored one of the layouts to include the <layout> element at its root, but I didn't refactor all the other layouts (layouts for other screen densities, languages, modules, etc.).

检查并确保所有所有可能的匹配布局均已配置为<layout>作为其根元素.

Check to make sure ALL the possible matching layouts are configured with <layout> as their root element.

请参阅此开发人员文档布局和绑定表达式

See this developer doc Layouts and binding expressions

这篇关于“由...引起的:java.lang.RuntimeException:视图必须具有标签"的实际含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆