Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when importing List type into xml file using Android Data binding

When I try to import the List class type into an xml file using Android Data Binding I receive the following error

Error: cannot find type element for List.

This error is really frustrating because I followed this documentation and it doesn't appear to be correct. Although there are quite a lot of data binding tutorials online, I can't manage to find one which covers this particular issue.

The data section in my xml file looks as follows:

<data>

    <import type="android.view.View" />

    <import type="java.util.List" />

    <import type="com.example.app.Book" />

    <variable
        name="books"
        type="List&lt;Book&gt;" />

</data>

List<Book> books = new ArrayList<>();
mBinding.setBooks(books);

Has anyone managed to solve this issue? I would really appreciate some help here.

like image 357
Wouter Avatar asked Sep 05 '16 10:09

Wouter


1 Answers

I met the problem just now,

Error:(34, 26) cannot find type element for List 

and solved it by replacing

<data>
    <import type="java.util.List"/>
    <variable
        name="list"
        type="List&lt;String&gt;"/>
</data>

with

<data>
    <variable
        name="list"
        type="java.util.List&lt;String&gt;"/>
</data>

Hope this can help you!


Besides, try to reference type with full qualified class name instead of short class name. Like

type="java.util.List&lt;com.example.app.Book&gt;"

because in my case, I found the import tag does not make any sense.

like image 150
xiangxing Avatar answered Oct 13 '22 00:10

xiangxing