Fixed NullPointerException on empty date

This commit is contained in:
Kai S. K. Engelbart 2019-10-23 17:17:15 +02:00
parent 33d48515b9
commit 1ded9df82b
2 changed files with 12 additions and 11 deletions

View File

@ -233,14 +233,12 @@ public class ChatWindow extends JFrame {
new Timer(5000, (evt) -> {
Messages unreadMessages = client.getUnreadMessages(client.getSender().getID());
System.out.println(unreadMessages.getMessage().get(0));
for (int i = 0; i < unreadMessages.getMessage().size(); i++) {
for (int j = 0; j < partnerChatList.size(); j++) {
if(partnerChatList.get(j).getRecipient().getID() == unreadMessages.getMessage().get(i).getMetaData().getSender()) {
for (int i = 0; i < unreadMessages.getMessage().size(); i++)
for (int j = 0; j < partnerChatList.size(); j++)
if (partnerChatList.get(j)
.getRecipient()
.getID() == unreadMessages.getMessage().get(i).getMetaData().getSender())
partnerChatList.get(j).appendMessage(unreadMessages.getMessage().get(i));
}
}
}
}).start();
contentPane.revalidate();
}

View File

@ -33,12 +33,15 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
setOpaque(true);
final String text = value.getContent().get(0).getText();
final String date = value.getMetaData().getDate() == null ? ""
: new SimpleDateFormat("dd.MM.yyyy hh:mm ")
.format(value.getMetaData().getDate().toGregorianCalendar().getTime());
setText(String.format(
"<html><p style=\"color:#d2d235\"><b><small>%s</b></small><br><p style=\"color:white\">%s</html>",
new SimpleDateFormat("dd.MM.yyyy hh:mm ")
.format(value.getMetaData().getDate().toGregorianCalendar().getTime()),
value.getContent().get(0).getText()));
date,
text));
return this;
}
}