我使用Realm for Android为我的应用创建数据库,但是我会尝试调用方法realm.beginTrasnaction()
,它告诉我Android Studio无法解析符号。
这是我的代码:
import io.realm.Realm;
public class playerCreator {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
}
这是我的gradle文件:
Project Gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath "io.realm:realm-gradle-plugin:3.5.0"
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块Gradle:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "tfdev.avventuratestuale"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
}
有谁知道我如何使用realm.beginTransaction()?
答案 0 :(得分:1)
好的,我已经修复了我的playerCreator类的构造函数,感谢Murat K.
import io.realm.Realm;
import io.realm.RealmObject;
public class playerCreator extends RealmObject{
public playerCreator(){
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
}
}