我是android初学者,我无法解决此崩溃 DatabaseException:无法将java.lang.String类型的对象转换为com.example.chat.groupConv类型
这是我的代码,仅打印第一个日志消息,应用程序崩溃并抛出该DataBaseException
public void onStart() {
super.onStart();
Query conversationQuery = mConvDatabase.orderByChild("time");
Log.v("conversationQuery", String.valueOf(conversationQuery));
FirebaseRecyclerAdapter<groupConv, ConvViewHolder> adapter =
new FirebaseRecyclerAdapter<groupConv, ConvViewHolder>(
groupConv.class,
R.layout.users_single_layout,
ConvViewHolder.class,
conversationQuery
) {
@Override
protected void populateViewHolder(final ConvViewHolder convViewHolder, final groupConv groupConv, int i) {
Query lastMessageQuery = mConvDatabase.limitToLast(1);
Log.v("populateViewHolder","populateViewHolder");
lastMessageQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.v("onDataChange","onDataChange");
//Messages msg =dataSnapshot.getValue(Messages.class);
//String data = msg.getMessage();
String data = dataSnapshot.child("message").getValue(String.class);
convViewHolder.setMessage(data, groupConv.isSeen());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
groupConv类
public class groupConv {
private String message, type;
private long time;
private boolean seen;
private String sender;
private String reciever0;
public groupConv() { }
public groupConv(String sender) {this.sender = sender; }
public groupConv(String message, String type, long time, boolean seen,String sender, String to) {
this.message = message;
this.type = type;
this.time = time;
this.seen = seen;
this.sender = sender;
reciever0 = to;
}
public String getFrom() { return sender; }
public void setFrom(String sender) { this.sender = sender; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public long getTime() { return time; }
public void setTime(long time) { this.time = time; }
public boolean isSeen() { return seen; }
public void setSeen(boolean seen) { this.seen = seen; }
public String getSender() { return sender; }
public void setSender(String sender) { this.sender = sender; }
public String getReciever0() { return reciever0; }
public void setReciever0(String reciever0) { this.reciever0 = reciever0; }
}
火力基地
希望任何人都可以帮助我!