public static String prepareTextForMessage(MailingHistoryDto mailingHistory) {
StringBuilder text = new StringBuilder("Mailings history: ");
if(mailingHistory!=null) {
if(mailingHistory.getStateLastMessage()!=null){
text.append("\nStatus last mailing: ").append(mailingHistory.getStateLastMessage().toString());
}
var countLine = 0;
for(var record : mailingHistory.getMailingList()){
var line = ++countLine+") "+convertDate(record.getSendDate()) + " | " +record.getCountMessages().toString()+ " pcs";
text.append("\n").append(line);
}
return text.toString();
}else {
return text + "\nYou didn't create mailings!";
}
}
The condition is not working, when you have no mailing history...and click on the button, nothing happens. And the bot should tell you that .. You didn't create mailings!"
java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "org.gnori.store.entity.MailingHistory.getMailingList()" is null
at org.gnori.data.dto.MailingHistoryDto.(MailingHistoryDto.java:20) ~[data-1.0-plain.jar!/:na]
at org.gnori.client.telegram.command.commands.MailingHistoryCommand.execute(MailingHistoryCommand.java:29) ~[classes!/:na]
at org.gnori.client.telegram.service.impl.MessageTypesDistributorServiceImpl.processCallbackQuery(MessageTypesDistributorServiceImpl.java:76) ~[classes!/:na]
at org.gnori.client.telegram.service.impl.MessageTypesDistributorServiceImpl.distributeMessageByType(MessageTypesDistributorServiceImpl.java:60) ~[classes!/:na]
at org.gnori.client.telegram.controller.UpdateController.processUpdate(UpdateController.java:26) ~[classes!/:na]
at org.gnori.client.telegram.controller.TelegramBot.onUpdateReceived(TelegramBot.java:31) ~[classes!/:na]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.telegram.telegrambots.meta.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27) ~[telegrambots-meta-6.1.0.jar!/:na]
at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:317) ~[telegrambots-6.1.0.jar!/:na]
In this part of the code.
public static String prepareTextForMessage(MailingHistoryDto mailingHistory) { StringBuilder text = new StringBuilder("Mailings history: "); if(mailingHistory!=null) { if(mailingHistory.getStateLastMessage()!=null){ text.append("\nStatus last mailing: ").append(mailingHistory.getStateLastMessage().toString()); } var countLine = 0; for(var record : mailingHistory.getMailingList()){ var line = ++countLine+") "+convertDate(record.getSendDate()) + " | " +record.getCountMessages().toString()+ " pcs"; text.append("\n").append(line); } return text.toString(); }else { return text + "\nYou didn't create mailings!"; } }
The condition is not working, when you have no mailing history...and click on the button, nothing happens. And the bot should tell you that .. You didn't create mailings!"
java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "org.gnori.store.entity.MailingHistory.getMailingList()" is null at org.gnori.data.dto.MailingHistoryDto.(MailingHistoryDto.java:20) ~[data-1.0-plain.jar!/:na]
at org.gnori.client.telegram.command.commands.MailingHistoryCommand.execute(MailingHistoryCommand.java:29) ~[classes!/:na]
at org.gnori.client.telegram.service.impl.MessageTypesDistributorServiceImpl.processCallbackQuery(MessageTypesDistributorServiceImpl.java:76) ~[classes!/:na]
at org.gnori.client.telegram.service.impl.MessageTypesDistributorServiceImpl.distributeMessageByType(MessageTypesDistributorServiceImpl.java:60) ~[classes!/:na]
at org.gnori.client.telegram.controller.UpdateController.processUpdate(UpdateController.java:26) ~[classes!/:na]
at org.gnori.client.telegram.controller.TelegramBot.onUpdateReceived(TelegramBot.java:31) ~[classes!/:na]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.telegram.telegrambots.meta.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27) ~[telegrambots-meta-6.1.0.jar!/:na]
at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:317) ~[telegrambots-6.1.0.jar!/:na]