Android MVVM:无法生成视图绑定器

时间:2017-10-11 12:36:54

标签: android mvvm data-binding android-databinding

我收到类似

的错误
Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -8

几分钟之前,我的代码运行良好,我能够运行该项目。我已经尝试了许多通过stackoverflow给出的解决方案,但无法找到解决此问题的实际解决方案。

我的应用级别gradle就像

android {

compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {

    applicationId "com.xyz.abc"
    minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
    targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    versionCode 1
    versionName "1.0"

    vectorDrawables.useSupportLibrary = true

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}

dataBinding {
    enabled = true
}

compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
  }

}

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}

dependencies {

  compile 'com.android.support:appcompat-v7:26.1.0'
  compile 'com.android.support.constraint:constraint-layout:1.0.2'
  compile 'com.android.support:design:26.1.0'
  compile 'com.android.support:cardview-v7:26.1.0'
  compile 'com.android.support:customtabs:26.1.0'

  compile 'com.android.support:support-v4:26.1.0'

}
apply plugin: 'com.google.gms.google-services'

非常感谢您方的任何意见。

1 个答案:

答案 0 :(得分:1)

我要找到解决上述问题的方法。这是我在标签下的布局文件中做的一些愚蠢的错误。我写了像

这样的代码
<variable
        name="deliveryPreferences"
        type="java.util.ArrayList&gt;String&lt;" />

而不是

<variable
        name="deliveryPreferences"
        type="java.util.ArrayList&lt;String&gt;" />

此处的区别在于&gt; &lt; 文字展示位置。我对这两者感到困惑。正确的解决方案是第二个,如果有人想从你的Java文件发送arraylist到xml文件。