数据绑定:找不到符号类BR [英] Data Binding: Cannot find symbol class BR
问题描述
我尝试在现有项目中使用数据绑定,但是无法构建它.
I try to use Data Binding in my existing project, but I can't get it to build.
在项目build.gradle
中使用:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
//Data Binding Beta
classpath "com.android.databinding:dataBinder:1.0-rc4"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
申请
apply plugin: 'com.android.databinding'
apply plugin: 'com.neenbedankt.android-apt'`
和在模块中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
apt 'com.android.databinding:compiler:1.0-rc1+'
}
我试图将数据绑定与RecyclerView/Fragment/ViewHolder/Adapter一起使用. 我使用的是Android Studio 1.4.1. 使用compileSdkVersion 23和buildToolsVersion"23.0.1". 我没有合适的,不同的gradle版本,尝试过它,证明读过我的classs/xml. 我还使用Butterknife(因为我的项目太大,无法立即更改所有内容)和其他(但不相关)库. 我同步并重建了项目,关闭/打开了Android Studio,并尝试使缓存无效.我从头开始构建了一个新"示例,效果很好.
I tried to use Data Binding with RecyclerView/Fragment/ViewHolder/Adapter.. I use Android Studio 1.4.1. With compileSdkVersion 23 and buildToolsVersion "23.0.1". I tried it without apt, different gradle versions, proof read my classes/xml.. I also use still Butterknife(since my project is too big to change everything at once) and other (but unrelevant) libraries. I synced and rebuild my project, I closed/opened Android Studio, I tried to invalidate caches. I build a 'fresh' example from start, which worked fine.
我的数据类"中的getter方法是@Bindable.
My getter Methods in my "data class" are @Bindable.
此外,未创建数据绑定包. (错误消息说它不存在)和Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21
Also, the databinding package is not created. (error message says it doesn't exist) and Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21
推荐答案
几乎每次尝试将ObservableList
与自定义对象一起使用时,都会出现Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21
错误.但是我发现,几乎每次我键入文字后都忘记了>
.傻我
因此,我的解决方案是进行检查:
I got the Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21
error almost everytime when I tried to use a ObservableList
with custom objects. But I found out, that almost everytime I forgot a >
after my type. Silly me.
So, my solution was to check for it:
<data>
<import type="android.databinding.ObservableArrayList"/>
<variable
name="dices"
type="ObservableArrayList<Dice>" /> //don't forget the '>' after Dice
</data>
这篇关于数据绑定:找不到符号类BR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!