Android- Cannot resolve symbol BaseObservable

倖福魔咒の 提交于 2020-01-14 10:45:49

问题


I am trying to implement data binding example in android and creating a POJO with bindable variables and i am getting this error ! please help. I am following this tutorial http://www.vogella.com/tutorials/AndroidDatabinding/article.html and here is my code

import android.databinding.BaseObservable;
import android.databinding.Bindable;

public class TemperatureData extends BaseObservable {
    private String location;
    private String celsius;

    public TemperatureData(String location, String celsius) {
        this.location = location;
        this.celsius = celsius;
    }

    @Bindable
    public String getCelsius() {
        return celsius;
    }

    @Bindable
    public String getLocation() {
        return location;
    }

    public  void setLocation(String location){
        this.location = location;
        notifyPropertyChanged(BR.location);
    }

    public void setCelsius(String celsius) {
        this.celsius = celsius;
        notifyPropertyChanged(BR.celsius);
    }

}

回答1:


You should add these lines of code to your app level gradle file as written in the 1.2 section

android {
    ....
    dataBinding {
        enabled = true
    }
}



回答2:


I was facing the same problem, I went to the build.gradle (Module:App) and added a block name dataBinding. I am listing my build.gradle code.

    apply plugin: 'com.android.application'

android {

    compileSdkVersion 28
    defaultConfig {
        applicationId "com.jadgroup.mvvm"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}


来源:https://stackoverflow.com/questions/45073291/android-cannot-resolve-symbol-baseobservable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!