当我尝试在房间数据库中放入一些数据时出现错误消息

时间:2019-10-23 12:35:41

标签: android android-room

我使用room创建了简单的脱机数据库,但出现此错误

  

原因:java.lang.RuntimeException:找不到以下实现:   com.test.test.AppDatabase.SplashScreenActivity_AppDatabase_Impl可以   不存在

代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    AppDatabase appDatabase = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "testDatabase").build();
    Categories category = new Categories();
    category.setId(0);
    category.setId(1);
    category.setCategoryName("Te");
    category.setCategoryName("Test");
    appDatabase.categoriesDao().insertAll(category);
}

@Entity
class Categories {

    @PrimaryKey
    int id;

    @ColumnInfo(name = "category_name")
    String categoryName;

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

    void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

}

@Dao
public interface CategoriesDao {

    @Insert
    void insertAll(Categories... categories);

}

@Database(entities = {Categories.class}, version = 1)
abstract class AppDatabase extends RoomDatabase {
    abstract CategoriesDao categoriesDao();
}

Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.**********"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.android.support:multidex:1.0.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    //Material Design
    implementation 'com.google.android.material:material:1.2.0-alpha01'
    //Butter Knife
    implementation 'com.jakewharton:butterknife:10.2.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
    //Volley
    implementation 'com.android.volley:volley:1.1.1'
    //Room
    implementation "androidx.room:room-runtime:2.2.0"
}

apply plugin: 'com.jakewharton.butterknife'

我在此网站上找到了许多解决方案,但都无法与我合作,谢谢。

1 个答案:

答案 0 :(得分:2)

  1. 首先,您在... else { mark[r] =true ; choose_elem_aux l n mark tmp ; } ... let choose l = nth l (Random.int (List.length l)) ;; let rec choose_elem_aux l n tmp = if n=0 then tmp else let r=choose l in if List.mem r tmp then choose_elem_aux l n tmp else choose_elem_aux l (n-1) (r::tmp) ;; let rec choose_elements l n = choose_elem_aux l n [] ;; 文件中添加了choose_elements [1...10_000] 7 ;;
string s = "I love dogs";
int i, j = 0;
List<char> array1 = new List<char>();
List<char> array2 = new List<char>();

for (i = 0; i < s.Length; i++)
{
    if (s.Length == j)
        break;

    if (Char.IsLetter(s[i]))
    {
        array1.Add(s[i]);
    }
    else
    {
        for (j = i; j < s.Length; j++)
        {
            if (Char.IsLetter(s[j]))
            {
                array2.Add(s[i]);
            }
            if (!Char.IsLetter(s[j]) || j == s.Length - 1)
            {
                if (array1.Count >= array2.Count)
                {
                    array2.Clear();
                }
                else
                {
                    array1.Clear();
                    array1.AddRange(array2);
                    array2.Clear();
                }
            }
        }
    }
} // How to convert array1 into String ?
  1. 任何一个都可以使您的annotationProcessor类在build.gradle内部成为静态对象,例如:
annotationProcessor "androidx.room:room-compiler:2.2.0"

AppDatabase而不是内部类创建单独的文件