gpt4 book ai didi

java - Android 房间显示错误 AppDatabase_Impl 不存在

转载 作者:行者123 更新时间:2023-12-01 14:14:33 24 4
gpt4 key购买 nike

我正在开发一个应用程序并为数据库添加空间,但它显示错误是

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.android/com.app.android.activities.AttendanceActivity}: java.lang.RuntimeException: cannot find implementation for com.app.android.db.AppDatabase. AppDatabase_Impl does not exist

在 gradle 文件中,我添加了所有内容。我的 gradle 文件如下所示。我不知道。问题是什么。此代码在另一个应用程序中工作。但它显示在这个应用程序中。请帮助我。

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId 'com.app.android'
minSdkVersion 14
targetSdkVersion 25
versionCode 16
// edumia versionCode 16
versionName "2.0.5"
// edumia versionName "2.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
jcenter()
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven {
url 'https://dl.bintray.com/ayz4sci/maven/'
}

}

allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(include: ['*.jar'], dir: 'libs')


compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5.1'

compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.facebook.shimmer:shimmer:0.1.0@aar'
compile 'com.afollestad.material-dialogs:core:0.9.3.0'
compile 'com.afollestad.material-dialogs:commons:0.9.3.0'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.uphyca:stetho_realm:2.0.0'
compile 'com.evernote:android-job:1.1.11'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
compile 'com.android.support:design:25.0.0'
compile 'com.ss.bannerslider:bannerslider:1.6.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.ayz4sci.androidfactory:downloadprogress:1.0.2'
compile('com.alibaba.android:ultraviewpager:1.0.6@aar') {
transitive = true
}


compile 'android.arch.lifecycle:extensions:1.0.0-rc1';
compile 'android.arch.persistence.room:runtime:1.0.0-rc1';
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-rc1';
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-rc1';
}

MainActivity.java

public class AttendanceActivity extends ActionBarActivity {
private Class_ class_;
private AppDatabase database;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

database = AppDatabase.getDatabase(getApplicationContext());
database.classDao().removeAllUsers();

Class_ aClass = new Class_(1,"model");
database.classDao().addClass(aClass);

Log.d(TAG, "added success");

}

AppDatabase.java

public abstract class AppDatabase extends RoomDatabase{

private static AppDatabase INSTANCE;
public abstract ClassDao classDao();
public static AppDatabase getDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE =
Room.databaseBuilder(context, AppDatabase.class, "edumiadatabase")
//Room.inMemoryDatabaseBuilder(context.getApplicationContext(), AppDatabase.class)
// To simplify the exercise, allow queries on the main thread.
// Don't do this on a real app!
.allowMainThreadQueries()
// recreate the database if necessary
.fallbackToDestructiveMigration()
.build();


}
return INSTANCE;
}

public static void destroyInstance() {
INSTANCE = null;
}
}

Class_.java

public class Class_ {
@PrimaryKey
public int id;
public String Class_;


public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getClass_() {
return Class_;
}

public void setClass_(String class_) {
Class_ = class_;
}

public Class_(int id, String class_){
this.id=id;
this.Class_ = class_;
}
}

ClassDao.java

@Dao
public interface ClassDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
void addClass(Class_ user);

@Query("delete from user")
void removeAllUsers();

}

最佳答案

我在 AppDatabase.java 添加了 @Database(entities = {Class_.class}, version = 1) 。数据库类的 @Database 注释和实体的 @Entity 。我给出的是正确的。然后问题就解决了。

关于java - Android 房间显示错误 AppDatabase_Impl 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47765691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com