2017-12-12 6 views
1

存在し、データベースのための部屋を追加しないエラーを示していますが、エラーが、私はすべてのものを追加していGradleのファイルでAndroidの部屋はAppDatabase_Implは私がアプリを開発しています

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ファイルは以下の通りです。知りません。何が問題ですか。このコードは別のアプリケーションで動作しています。しかし、それはこのアプリケーションで示しています。親切に私を助けてください。

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:[email protected]' 
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:[email protected]') { 
    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(); 

} 
+0

データベースクラスの '@ Database'アノテーションと、あなたのエンティティの' @ Entity'が欠けているようです。 – Thorbear

+0

'@ Database'と' @ Entity'を追加しましたが、別のエラーが表示されます。https://developer.android.com/training/data-storage/room/index.html –

+0

新しいエラーは何ですか?これらの注釈はRoom to workに必要ですが、新しいエラーはあなたがもう少し進んでいくことを意味します。 野生の推測では、私は 'ユーザからの削除 'に関してそのようなテーブルがない(あなたのエンティティは' class_'と呼ばれるテーブルを生成します)ので不平を言います。 私はRoom 1.0.0がリリースされたので、rc1を使い続ける理由はないことにも気付くでしょう。 – Thorbear

答えて

2

私はAppDatabase.javaで@Database(entities = {Class_.class}, version = 1)を追加しました。データベースクラスの@Databaseアノテーション、エンティティの@Entity。私は正しいとしてきました。その後、問題は解決しました。

0

私も私のアプリモジュールの私の

build.gradleに正しい依存関係を追加した後、同じ問題に直面していました。私の問題データベース層を分離するために別のモジュールを使用しました。私の依存関係をbuild.gradleの対応モジュールに移動しました。私の問題を解決しました。

これは他の人に役立つことを望みます。

関連する問題