【问题标题】:Unclosed files for the types '[io.rearealm.com_example_myapplication_UserRealmProxy]'; these types will not undergo annotation processing'[io.rearealm.com_example_myapplication_UserRealmProxy]' 类型的未关闭文件;这些类型不会进行注释处理
【发布时间】:2019-05-04 21:04:57
【问题描述】:

我正在开发应用程序,但我已经实现了领域,但我从构建中收到以下错误

类型的未关闭文件 '[io.realm.com_example_myapplication_UserRealmProxy]';这些类型 不会进行注解处理

错误:“android.graphics.Bitmap”类型的字段“图标”不是 支持。

User.Java 模型类下面

@RealmClass
public class User extends RealmObject implements IChatUser {
    Integer id;
    String name;
    Bitmap icon;

    public User() {
    }

    public User(int id, String name, Bitmap icon) {
        this.id = id;
        this.name = name;
        this.icon = icon;
    }

    @Override
    public String getId() {
        return this.id.toString();
    }

    @Override
    public String getName() {
        return this.name;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public Bitmap getIcon() {
        return this.icon;
    }


    @Override
    public void setIcon(Bitmap icon) {
        this.icon = icon;
    }
}

below realm implementation

Realm.init(this);
        realm = Realm.getDefaultInstance();
        realm.beginTransaction();

        User userModel =  realm.createObject(User.class);
        realm.copyToRealmOrUpdate(userModel);






        //Load saved messages
        loadMessages(realm);

在 app.gradle 下

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.core:core:1.0.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    implementation 'com.github.bassaer:chatmessageview:2.0.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

【问题讨论】:

    标签: java android realm


    【解决方案1】:

    错误:不支持“android.graphics.Bitmap”类型的字段“图标”。

    您只能将 Realm 支持的类型存储在模型类中。名单在这里:https://realm.io/docs/java/latest/#field-types

    在您的情况下,您需要将 Bitmap 转换为字节数组并返回到 getter 和 setter。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 2011-11-29
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 2012-10-03
      相关资源
      最近更新 更多