首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在聊天室数据库中添加另一个表时出错

在聊天室数据库中添加另一个表时出错
EN

Stack Overflow用户
提问于 2020-02-02 23:43:09
回答 1查看 95关注 0票数 0

我已经在我的应用程序中使用了房间数据库。现在,我已经将我的项目迁移到了androidX,因此更改了依赖关系。

现在,当我添加一个表并尝试运行项目时,我收到多个文件的错误:

代码语言:javascript
复制
error: cannot find symbol class BR

下面是我的模型类:

代码语言:javascript
复制
@Keep
@Entity
public class Notification {
    private String title;
    private String body;

    public Notification(String title, String body) {
        this.title = title;
        this.body = body;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
}

下面是我的NotificationDao类:

代码语言:javascript
复制
   public abstract class NotificationDao {
    @Insert(onConflict = REPLACE)
    public abstract void insert(Notification notification);

    @Query("DELETE FROM Notification")
    public abstract void deleteAll();
}

下面是为迁移编写的代码:

代码语言:javascript
复制
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE IF NOT EXISTS Notification (`title` TEXT, `body` TEXT)");
        }
    };

我已经将版本从%1增加到% 2。

我也在build中添加了这个。

代码语言:javascript
复制
    Room.databaseBuilder(
                application,
                MyDatabase.class,
                Configuration.DB_NAME
        ).addMigrations(MyDatabase.MIGRATION_1_2).build();

app.gradle是:

代码语言:javascript
复制
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

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


android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 211990017
        versionName "2.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        // Write out the current schema of Room
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),]
            }
        }
        vectorDrawables.useSupportLibrary = true
        project.archivesBaseName = "xxxx";
        multiDexEnabled true
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -fexceptions"
                arguments "-DANDROID_TOOLCHAIN=clang",
                        "-DANDROID_STL=c++_shared",
                        "-DANDROID_PLATFORM=android-21"

            }
        }

    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/jniLibs']
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    signingConfigs {
        release {
            storeFile file("keystores/xxxx")
            storePassword "xxxx"
            keyAlias "xxxx"
            keyPassword "xxxx"
        }
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
            proguardFiles getDefaultProguardFile('proguard-android.txt')
            signingConfig signingConfigs.release
        }
        debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
            proguardFiles getDefaultProguardFile('proguard-android.txt')
            signingConfig signingConfigs.release
        }
    }
    dataBinding {
        enabled true
    }
    buildToolsVersion '28.0.3'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    flavorDimensions "environment"
    productFlavors {
        development {
            applicationId "com.emproto.xxxx"
            resValue "string", "content_provider", "com.xxx.xxxx.fileprovider"
        }
        production {
            applicationId "com.xxxx"
            resValue "string", "content_provider", "com.xxxx.fileprovider"
        }
    }
    splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true
            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86 and x86_64.
            // Resets the list of ABIs that Gradle should create APKs for to none.
            reset()
            // Specifies a list of ABIs that Gradle should create APKs for.
            include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"

            // Specifies that we do not want to also generate a universal APK that includes all ABIs.
            universalApk true
        }
    }

}

ext.abiCodes = ['x86': 1, 'x86_64': 2, 'armeabi-v7a': 3, 'arm64-v8a': 4]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def baseVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
        if (baseVersionCode != null) {
            output.versionCodeOverride = Integer.valueOf(baseVersionCode + variant.versionCode)
        }
    }
}

ext {
    retrofitVersion = '2.3.0'
    daggerVersion = '2.11'
    supportLibVersion = '28.0.0'
    googleLibVersion = '16.0.1'
    frescoLibVersion = '2.0.0'
    moEngageVersion = '9.8.02'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

    /*Dagger 2 is a fully static and compile time dependency injection framework*/
    implementation "com.google.dagger:dagger:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
    implementation 'javax.annotation:jsr250-api:1.0'

    /*LiveData and ViewModel*/
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    /*
                annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
            */

    /*Room*/
    implementation 'androidx.room:room-runtime:2.2.3'
    annotationProcessor 'androidx.room:room-compiler:2.2.3'

    // Java8 support for Lifecycles
    implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'

    /*Retrofit*/
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

    /*For loading images from network*/
    implementation "com.facebook.fresco:fresco:$frescoLibVersion"
    implementation "com.facebook.fresco:imagepipeline-okhttp3:$frescoLibVersion"

    /*For the left menu*/
    implementation 'com.yarolegovich:sliding-root-nav:1.1.0'

    /*For the typing indicator*/
    implementation 'com.github.channguyen:adv:1.0.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'

    /*For Graphs */
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    /*For firebase push notifications */
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation "com.google.firebase:firebase-core:16.0.6"
    /*For Database debugging */
    //    debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

    /*For S - Health */
    implementation files('libs/s-health/samsung-health-data-v1.3.0.jar')
    implementation files('libs/s-health/sdk-v1.0.0.jar')

    /*For Google-Fit */
    implementation "com.google.android.gms:play-services-fitness:$googleLibVersion"
    implementation "com.google.android.gms:play-services-auth:$googleLibVersion"

    /*Circular floating action bar*/
    implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'

    // For animated GIF support
    implementation "com.facebook.fresco:animated-gif:$frescoLibVersion"

    /*Circular seekbar - Feelings*/
    implementation 'com.github.JesusM:HoloCircleSeekBar:v2.2.2'

    /*Circular Layout - Feelings*/
    implementation 'com.github.andreilisun:circular-layout:1.0'

    /*For offline log synchronization*/
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

    /*Wheel picker - RecordCholesterol*/
    implementation 'com.weigan:loopView:0.1.2'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
        transitive = true;
    }

    /*Image Cropper - Profile Fragment*/
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'

    /*PDF  Viewer - Prescription/Report */
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    api 'com.thedesigncycle.ui:views:0.3.1'
    implementation 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'
    implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
    implementation files('libs/omron/jp.co.omron.healthcare.omoron_connect.wrapper-1.3.jar')
    implementation 'com.appsee:appsee-android:+'
    implementation 'com.github.florent37:viewtooltip:1.1.6'
    implementation 'com.asksira.android:cameraviewplus:0.9.5'
    implementation 'me.zhanghai.android.materialratingbar:library:1.3.1'

    implementation 'com.priyankvex:smarttextview:1.0.1'
    implementation 'com.github.flipkart-incubator:android-inline-youtube-view:1.0.3'
    implementation 'com.github.varunest:sparkbutton:1.0.6'

    implementation 'io.branch.sdk.android:library:3.2.0'




    //foo transitions in trel home(doctor names)
    implementation "com.andkulikov:transitionseverywhere:1.8.1"

    //AppsFlyer
    implementation 'com.appsflyer:af-android-sdk:4.10.3'
    implementation 'com.android.installreferrer:installreferrer:1.0'

    //picasso image loading lib
    implementation 'com.squareup.picasso:picasso:2.5.2'

    //Facebook analytics dependency
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'

    //Moengage dependency
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.moengage:moe-android-sdk:$moEngageVersion"
}
apply plugin: 'com.google.gms.google-services'

如何修复错误?

EN

回答 1

Stack Overflow用户

发布于 2020-02-03 03:11:52

没有在model类中添加主键是导致问题的原因。我认为更具体的错误信息应该来自android studio的房间数据库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60027746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档