我正在为我的项目实现缓存并使用Room,但不知道出了什么问题,我将其用于另一个模型,它可以正常工作,但对于复杂的模型,则可以编译错误。
原因:long无法转换为元素
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: longcannot be converted to an Element
at com.sun.tools.javac.main.Main.compile(Main.java:553)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:48)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:35)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:51)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:39)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:207)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:133)
at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
我也读过this
。起初,关于id的错误很多,它说您在数据库中使用了相同的名称,因为我在模型中嵌套了Inviter
之类的对象,并且也嵌套了id
。
线程模型
@Entity
public class Thread {
@ColumnInfo(name = "thread_id")
@PrimaryKey
private long id;
private long joinDate;
@Embedded
private Inviter inviter;
@Embedded
private LastMessageVO lastMessageVO;
@ColumnInfo(name = "thread_title")
private String title;
@TypeConverters(DataTypeConverter.class)
private List<Participant> participants;
private long time;
private String lastMessage;
private String lastParticipantName;
private boolean group;
private long partner;
@ColumnInfo(name = "thread_image")
private String image;
private long unreadCount;
private long lastSeenMessageId;
private long partnerLastMessageId;
private long partnerLastSeenMessageId;
private long partnerLastDeliveredMessageId;
private int type;
private boolean mute;
private String metadata;
private boolean canEditInfo;
private long participantCount;
邀请者模型
public class Inviter {
@ColumnInfo(name = "Inviter_id")
private long id;
private String name;
private String firstName;
private String lastName;
private long notSeenDuration;
LastMessageVO
@ColumnInfo(name = "lastMessageVO_id")
private long id;
private String uniqueId;
private String message;
private boolean edited;
private boolean editable;
@ColumnInfo(name = "lastMessageVO_time")
private long time;
@Embedded
private Participant participant;
@Embedded
private ReplyInfoVO replyInfoVO;
@Embedded
private ForwardInfo forwardInfo;
我的 dao 班
@Dao
public interface MessageDao {
@Insert(onConflict = REPLACE)
void insertContact(Contact t);
@Insert(onConflict = REPLACE)
void insertContact(List<Contact> t);
@Query("select * from Contact")
List<Contact> getContact();
@Query("select * from Thread")
List<Thread> getThread();
@Insert(onConflict = REPLACE)
void insertThread(List<Thread> threads);
}
答案 0 :(得分:0)
答案是关于您无法将对象保存到房间中,您必须忽略它,然后以另一种方式保存嵌套对象。而且由于我在该嵌套对象中有很长的参数,因此它的名称为longcannot be converted to an Element
。
我使用this并解决了问题。