What the actual meaning `Caused by: java.lang.Runt

2020-07-06 02:26发布

问题:

Please inform me if knowing whats tag that wanted.

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

__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

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

ERROR 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)

回答1:

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>.

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.).

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



回答2:

NO idea, but working.