Java 如何将源类型转换器转换为房间
我正在开发并实现一个新闻应用程序,但我无法将模型类转换为低于模型类的typeconverterJava 如何将源类型转换器转换为房间,java,android,type-conversion,android-room,Java,Android,Type Conversion,Android Room,我正在开发并实现一个新闻应用程序,但我无法将模型类转换为低于模型类的typeconverter @Entity @ForeignKey(entity = Source.class,parentColumns = "source", childColumns = "content") public class Article { @PrimaryKey @SerializedName("source") @Expose @ColumnInfo(name ="sou
@Entity
@ForeignKey(entity = Source.class,parentColumns = "source", childColumns = "content")
public class Article {
@PrimaryKey
@SerializedName("source")
@Expose
@ColumnInfo(name ="source")
@TypeConverters(SourceTypeConverter.class)
private Source source;
public Source getSource() {
return source;
}
public void setSource(Source source) {
this.source = source;
}
@SerializedName("author")
@Expose
@ColumnInfo(name = "author")
private String author;
@SerializedName("title")
@Expose
@ColumnInfo(name = "title")
private String title;
@SerializedName("description")
@Expose
@ColumnInfo(name = "description")
private String description;
@SerializedName("url")
@Expose
@ColumnInfo(name = "url")
private String url;
@SerializedName("urlToImage")
@Expose
@ColumnInfo(name = "urlToImage")
private String urlToImage;
@SerializedName("publishedAt")
@Expose
@ColumnInfo(name = "publishedAt")
private String publishedAt;
@SerializedName("content")
@Expose
@ColumnInfo(name = "content")
private String content;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrlToImage() {
return urlToImage;
}
public void setUrlToImage(String urlToImage) {
this.urlToImage = urlToImage;
}
public String getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(String publishedAt) {
this.publishedAt = publishedAt;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
在我的SourceTypeConverter类下面
public class SourceTypeConverter {
@TypeConverter
public static Source ConvertSource(Source source){
return source == null ? null : new Source(source);
}
}
下面是Source.java
公共类源{
@SerializedName("id")
@Expose
private String id;
@SerializedName("name")
@Expose
private String name;
public Source(Source source) {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
下面是C:\Users\Edgar\Desktop\Sport News\app\src\main\java\Edgar\yodgorbek\sportnews\model\Article。java:18:错误:无法确定如何将此字段保存到数据库中。可以考虑为其添加类型转换器。
私人来源
below my database class
@Database(entities = {Article.class}, version = 1, exportSchema = false)
public abstract class SportNewsDatabase extends RoomDatabase {
public abstract SportNewsDao sportNewsDao();
}
根据我们在linkedin的聊天,我可以说你是一个非常忘恩负义的人。您的问题是,文件室无法转换模型中的文件类型源。所以您需要创建从源类到sqlite支持的类型的转换器 根据你最新发布的代码,我可以说你试图做错事。您有两个表:Source和Article。您希望在文章中存储指向源代码的链接 删除您的类型转换器 读这个 简而言之,您需要在本文中为源代码创建外键。这是一对一的关系。
请发布您的转换器类以及您需要转换的字段?@w201我无法转换这就是我发布代码的原因请帮助我什么是源类?现在,您的类型转换器根本没有意义。它返回数据库不支持的类型。提供源代码class@w201我已经添加了我的数据库,我也有错误,我也有错误,请检查我上面的更新帖子,我添加了代码,请检查,请检查我的更新代码,我已经按照你告诉我的做了,但我也有错误