我正在尝试使用firebase构建聊天应用程序我在firebase recyclerview适配器中遇到问题它显示此错误
无法将java.util.HashMap类型的值转换为String
我的结构用户 - > IDuser - >聊天 - > id chat - >消息 - > id消息
聊天包含用户的所有deffrente对话
我的代码:
@Override
protected void onStart() {
super.onStart();
Query query = FirebaseDatabase.getInstance().getReference().child("User").child(Cuid).child("Chat").child(idconvC).child("messages").getRef();
FirebaseRecyclerOptions<Message> options =
new FirebaseRecyclerOptions.Builder<Message>()
.setQuery(query,Message.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Message,Conv.ConvViewHolder>
(options) {
@NonNull
@Override
public Conv.ConvViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.message for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.messagerow, parent, false);
return new Conv.ConvViewHolder(view);
}
@Override
protected void onBindViewHolder (@NonNull Conv.ConvViewHolder viewHolder,final int position,@NonNull Message model) {
if (model.getUsername().equals(Cusername)) {
viewHolder.seturi(getApplicationContext(),model.getUri());
viewHolder.setusername(model.getUsername());
viewHolder.setmsg(model.getMessage());
viewHolder.itemView.setBackgroundColor(Color.parseColor("#d3d3d3"));
// Gravity right
}
else {
viewHolder.seturi(getApplicationContext(),model.getUri());
viewHolder.setusername(model.getUsername());
viewHolder.setmsg(model.getMessage());
// Gravity left
}
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}