在Android中使用数据绑定错误:包*。*。databinding不存在 [英] Using data-binding in android error: package *.*.databinding does not exist

查看:847
本文介绍了在Android中使用数据绑定错误:包*。*。databinding不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在android应用中实现数据绑定。 是我要设置的链接。即使在完成所有必要的实现后,我在gradle-build中也收到以下错误:

I'm trying to implement data-binding in android app. This is the link I'm following to set it up. Even after doing all the necessary implements, I'm getting the following error in gradle-build:


错误:包com.example.satpracticeapp .databinding不存在。

error: package com.example.satpracticeapp.databinding does not exist.

(此包是我在MainActivity.java文件中导入的包)
我尝试了(数据绑定编译器),但没有成功。

(This package is what I'm importing in my MainActivity.java file) I tried this (the data-binding compiler), but it didn't work.

问题是我已经成功尝试了使用数据绑定的hello-world应用程序,并且可以正常工作。但是,当我尝试在几周前制作的应用程序中实现它时,出现了上面提到的错误。在寻找解决方案时,我将gradle文件从成功的hello world应用程序复制粘贴到了我的旧应用程序-仍然无法解决问题。

The problem is I've already successfully tried a hello-world app using data-binding and it works. But, when I try to implement it in an app I made a few weeks ago, I get the error I mentioned above. Searching for the solutions, I copy-pasted the gradle files from my successful hello world app to my old app - that too didn't work out.

这是我的应用程序level build.gradle

Here is my app level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.satpracticeapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.0'
}

这是项目级别build.gradle文件的buildscript:

And here's the buildscript of the project level build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

以下是三个文件的最低版本的链接(如果需要)

Here are the links to the minimal version of the three files (if it's needed)


  1. MainActivity.java

  2. ViewModel.java

  3. activity_main.xml

  1. MainActivity.java
  2. ViewModel.java
  3. activity_main.xml

经过大量的头发拔除后,我无法弄清解决方案并得到相同的构建错误一次又一次。
因此,作为一个临时解决方案,我正在尝试将我的类和布局复制粘贴到正在使用的hello world项目中。我错过了什么?

After much hair-pulling, I couldn't figure out the solution and getting the same build error again and again. So, as a temporary solution, I'm trying to copy-paste my classes and layouts in the working hello world project. What am I missing?

编辑:

搜索后,我回到了代码。逐字检查它,并在xml文件中的绑定变量的名称中发现了键入错误。
现在一切正常!

After a few hours of pointless searching, I went back to my code. Checked it word by word and found a typing mistake at the name of a binding variable in the xml file. Everything works fine now!

推荐答案

我遇到了同样的问题,原来是一个重复的符号声明我的* .java类。它显示在Gradle控制台中,但有点隐藏在数据绑定错误中。我大约有72个数据绑定错误,并且这个重复的符号错误在中间,所以很容易错过。

I had the same issue, turned out to be a duplicate symbol declaration in one of my *.java classes. It's shown in the Gradle console but it was kinda hidden among the databinding errors. i had about 72 data binding errors and this duplicate symbol error was in the middle so it's easy to miss.

这篇关于在Android中使用数据绑定错误:包*。*。databinding不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆