首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >房间ORM型变频器误差

房间ORM型变频器误差
EN

Stack Overflow用户
提问于 2017-11-22 13:15:17
回答 1查看 2.2K关注 0票数 5

我一直收到以下错误:

无法确定如何将此字段保存到数据库中。您可以考虑为它添加一个类型转换器。

我在我的数据库类中将@Type转换器添加到了对转换器方法和@TypeConverters注释中。

DownloadItem.java

代码语言:javascript
复制
  @Entity(tableName = "downloads")
    public class DownloadItem implements Serializable {

        public enum DownloadStatus {
            None(0),
            Downloading(1),
            Suspended(2),
            Completed(3),
            Deleted(4),
            Expired(5);

            private final int numeral;

            @TypeConverter
            public static DownloadStatus getDownloadStatus(int numeral){
                for(DownloadStatus ds : values()){
                    if(ds.numeral == numeral){
                        return ds;
                    }
                }
                return null;
            }

            @TypeConverter
            public static Integer getDownloadStatusInt(DownloadStatus status){
                return status.numeral;
            }

            DownloadStatus(int num){
                this.numeral = num;
            }
        }

        @TypeConverters(DownloadStatus.class)
        @ColumnInfo(name = "download_status")
        public DownloadStatus downloadStatus;

        @PrimaryKey
        @NonNull
        private int contentId;

       @Ignore
        public DownloadItem() {
        }

     public DownloadItem(DownloadStatus downloadStatus, int contentId) {
            this.downloadStatus = downloadStatus;
            this.contentId = contentId;
        }
      }

DownloadDatabase.java

代码语言:javascript
复制
    @Database(entities = {DownloadItem.class}, version = 1)
@TypeConverters({DownloadItem.DownloadStatus.class, PlayerType.class})
public abstract class DownloadDatabase extends RoomDatabase {

    public abstract DownloadItemStore downloadItemStore();

    private static final String DB_NAME = "download.db";
.......
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-23 13:06:54

应该是getDownloadStatusIntint,而不是Integer

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47435686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档