Search code examples
androidrealmcannot-find-symbol

Realm method "Cannot Resolve Symbol"


I'm using Realm for Android to create a database for my app but wheme i go to try to call the method realm.beginTrasnaction(), it tell me that Android Studio cannot resolve symbol.

Here's my piece of code:

import io.realm.Realm;

public class playerCreator {

Realm realm = Realm.getDefaultInstance();

realm.beginTransaction();

}

And here's my gradle files:

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
}

Module 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'
}

Does anybody know how can i use realm.beginTransaction() ?


Solution

  • Ok, i've fixxed added the constructor of my playerCreator class, thanks to Murat K.

    import io.realm.Realm;
    import io.realm.RealmObject;
    
    public class playerCreator extends RealmObject{
    
        public playerCreator(){
    
            Realm realm = Realm.getDefaultInstance();
    
            realm.beginTransaction();
    
        }
    }