Reputation:
I am using Room Persistence Library
to create a database in my android application.
When trying to make a class named User
as an Entity
, I added @Entity
annotation above my User
class but android studio displays an error saying cannot resolve symbol Entity
.
@Entity <--------cannot resolve symbol Entity
public class User {
@PrimaryKey <--------cannot resolve symbol PrimaryKey
private String userName;
private String userPhoneNumber;
}
I also tried to add @PrimaryKey
annotation to one of the data members of User
class but i get the same error.
What am i doing wrong here ?
Logs from Gradle Console
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:generateDebugAndroidTestResValues
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:splitsDiscoveryTaskDebugAndroidTest
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar
BUILD SUCCESSFUL in 2m 38s
22 actionable tasks: 22 executed
Gradle build
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.Nick.phonebook_database"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Upvotes: 0
Views: 1423
Reputation: 7415
You need to import the Room dependency also.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'android.arch.persistence.room:runtime:1.0.0-beta1'
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-beta1"
}
After adding the dependency click Sync Now
.
Upvotes: 1