我想在recyclerview中显示群聊消息,但在logcat中有此警告 我为这个错误进行了很多搜索,找不到正确的解决方案...
模型类
public class Groups {
private String groupName;
private String Admin;
private String push_id;
public MessageG messageG;
public Groups() {
}
public Groups(String groupName, String Admin, String push_id, MessageG messageG) {
this.groupName = groupName;
this.Admin = Admin;
this.push_id = push_id;
this.messageG = messageG;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getAdmin() {
return Admin;
}
public void setAdmin(String admin) {
Admin = admin;
}
public String getPush_id() {
return push_id;
}
public void setPush_id(String push_id) {
this.push_id = push_id;
}
public MessageG getMessageG() {
return messageG;
}
public void setMessageG(MessageG messageG) {
this.messageG = messageG;
}
}
对于孩子:
public class MessageG
{
public String id;
public String name;
public String userid;
public String msg;
public String date;
public long time;
public MessageG() {}
public MessageG(String id, String name, String userid, String msg, String date, long time) {
this.id = id;
this.name = name;
this.userid = userid;
this.msg = msg;
this.date = date;
this.time = time;
}
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;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
}
按钮的侦听器(发送消息):
btn_send_message.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String message = text_send.getText().toString();
if(message.equals(""))
{
Toast.makeText(GroupChatActivity.this, "Empty !", Toast.LENGTH_SHORT).show();
}
else
{
//SendMessageInfoToDatabase();
GroupNameRef = FirebaseDatabase.getInstance().getReference("Groups").child("Messages");
String id = GroupNameRef.push().getKey();
//---GET DATE
Calendar calForDate = Calendar.getInstance();
SimpleDateFormat currentDateFormat = new SimpleDateFormat("MMM dd, yyyy");
currentDate = currentDateFormat.format(calForDate.getTime());
//---------------------
//--- the time
Calendar calForTime = Calendar.getInstance();
SimpleDateFormat currentTimeFormat = new SimpleDateFormat("hh:mm");
currentTime = currentTimeFormat.format(calForTime.getTime());
//---------------------
assert id != null;
GroupMessageKeyRef = GroupNameRef.child(id);
Map<String, Object> messageInfoMap = new HashMap<>();
messageInfoMap.put("id", id);
messageInfoMap.put("name", CurrentUserName);
messageInfoMap.put("userid", fuser.getUid());
messageInfoMap.put("msg", message);
messageInfoMap.put("date", currentDate);
messageInfoMap.put("time", currentTime);
GroupMessageKeyRef.setValue(messageInfoMap);
text_send.setText("");
}
}
});
我的适配器:
public class GroupMessageAdapter extends RecyclerView.Adapter<GroupMessageAdapter.GroupMessageViewHolder>
{
public static final int MSG_RECEIVERS = 1;
public static final int MSG_SENDER = 0;
private List<Groups> mMessageList;
private Context mContext;
public GroupMessageAdapter(List<Groups> mMessageList, Context mContext) {
this.mMessageList = mMessageList;
this.mContext = mContext;
}
@NonNull
@Override
public GroupMessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
if(viewType == MSG_SENDER)
{
View view = LayoutInflater.from(mContext).inflate(R.layout.chat_item_sender, parent, false);
GroupMessageViewHolder gmvh = new GroupMessageViewHolder(view);
return gmvh;
}
else
{
View view = LayoutInflater.from(mContext).inflate(R.layout.chat_item_receivers, parent, false);
GroupMessageViewHolder gm = new GroupMessageViewHolder(view);
return gm;
}
}
public class GroupMessageViewHolder extends RecyclerView.ViewHolder
{
private TextView messages_textView;
public GroupMessageViewHolder(@NonNull View itemView)
{
super(itemView);
messages_textView = itemView.findViewById(R.id.group_chat_text_display);
}
}
@Override
public void onBindViewHolder(@NonNull final GroupMessageViewHolder groupMessageViewHolder, int position)
{
Groups groups = mMessageList.get(position);
groupMessageViewHolder.messages_textView.setText(groups.getMessageG().getMsg());
}
@Override
public int getItemCount()
{
return mMessageList.size();
}
@Override
public int getItemViewType(int position)
{
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
assert firebaseUser != null;
if(mMessageList.get(position).getMessageG().getUserid().equals(firebaseUser.getUid()))
{
return MSG_SENDER;
}
else
{
return MSG_RECEIVERS;
}
}
}
错误是:
W / ClassMapper:在以下位置未找到(推送产生的密钥)的设置器/字段 课
我的数据库: