java - '[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'
}
解决方案
错误:不支持“android.graphics.Bitmap”类型的字段“图标”。
您只能将 Realm 支持的类型存储在模型类中。列表在这里:https ://realm.io/docs/java/latest/#field-types
在您的情况下,您需要将 Bitmap 转换为字节数组并返回到 getter 和 setter。
推荐阅读
- python - 脚本中的 Sympy Solver 不打印返回值
- ios - “'(CLLocationManager, [CLLocation]) -> ()' 类型的值没有成员 'delegate'” 快速映射错误
- python - ImportError:无法导入测试模块
- angular - Angular 8 Reactive Form:复选框不可点击
- r - 如何在R中匹配模式后提取一定长度的子字符串?
- go - 通过 reflect.Value.SetString 设置新字符串
- big-o - 嵌套循环的大 O (int j = 0; j < i; j++)
- java - 将按钮图形与图像进行比较
- python - 使用多线程调度非周期性事件
- vue.js - 是否可以在渲染时查询数据并返回结果