What the actual meaning `Caused by: java.lang.RuntimeException: view must have a tag`?

后端 未结 9 1900
轮回少年
轮回少年 2021-02-20 06:25

Please inform me if knowing whats tag that wanted.

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

__BaseActivity.java

          


        
相关标签:
9条回答
  • 2021-02-20 06:34

    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

    0 讨论(0)
  • 2021-02-20 06:36

    I converted my layout by wrapping it in <layout> tags, but I forgot to move the namespace declarations to the opening <layout> tag:

    Before

    <layout>
        <androidx.constraintlayout.widget.ConstraintLayout 
         xmlns:android="http://schemas.android.com/apk/res/android">
    

    After

    <layout xmlns:android="http://schemas.android.com/apk/res/android">
        <androidx.constraintlayout.widget.ConstraintLayout>
    
    0 讨论(0)
  • 2021-02-20 06:37

    this happened to me because one layout wasn't present for all resolution (it was only in layout and layout-normal).

    0 讨论(0)
  • 2021-02-20 06:48

    This happened to me due to the library's layout file (the one for which the error was flagged) having the same name as another one in the app module. Both used data binding.

    0 讨论(0)
  • 2021-02-20 06:49

    NO idea, but working.

    0 讨论(0)
  • 2021-02-20 06:50

    Please convert the XML layout into data binding. this may cause this exception.like

    <layout>
    xml components here...
    </layout>
    
    0 讨论(0)
提交回复
热议问题