首页 > 解决方案 > '[io.rearealm.com_example_myapplication_UserRealmProxy]' 类型的未关闭文件;这些类型不会进行注释处理

问题描述

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

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

标签: javaandroidrealm

解决方案


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

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

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


推荐阅读