Field in my project is null and I don't have idea why. I don't initalize in project any autowired variable like new BingoGameService(); - so I don't know why I got null.
public class MessageReaction extends ListenerAdapter {
@Autowired
BingoGameService bingoGameService; //NULL
@Override
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
if(event.getMessage().getContentRaw().equals("!createBingo")) bingoGameService.createBingoGameForUser(event.getAuthor().getIdLong());
This is my service class:
@Service
public class BingoGameService {
@Autowired
DiscordUserRepo discordUserRepo;
@Autowired
BingoBoardRepo bingoBoardRepo;
@Autowired
GameMechanics gameMechanics;
public void createBingoGameForUser(Long id) {
if(bingoBoardRepo.findById(1L).isPresent()){
String[][] officialBingoBoard = bingoBoardRepo.findById(1L).get().getBingoBoard();
int[][] scoreBoard = gameMechanics.createScoreBoard(3,3);
DiscordUser discordUserToSave = new DiscordUser();
BingoGame bingoGame = new BingoGame(discordUserToSave, officialBingoBoard, scoreBoard);
discordUserToSave.setUserId(id);
discordUserToSave.setBingoGame(bingoGame);
discordUserRepo.save(discordUserToSave);
}
}