我正在开发应用程序,但是我已经实现了领域,但是我在构建过程中遇到了以下错误
这些类型的未关闭文件 '[io.realm.com_example_myapplication_UserRealmProxy]';这些类型 不会进行注释处理
错误:“ android.graphics.Bitmap”类型的字段“ icon”不是 支持。
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'
}
答案 0 :(得分:1)
错误:“ android.graphics.Bitmap”类型的字段“ icon”不受支持。
您只能在模型类中存储Realm支持的类型。列表在这里:https://realm.io/docs/java/latest/#field-types
在这种情况下,您需要将位图转换为字节数组,然后再返回到getter和setter中。