From de728745f6ed8195d3725e6b59ec3035895d1d8a Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 6 May 2022 19:26:34 +0200 Subject: [PATCH] list all games in gameschedule prevent nullpointer exception for empty games --- .../ch/zhaw/projekt2/turnierverwaltung/Tournament.java | 4 ++-- .../main/gameScheduleView/GameDecorator.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java index bd7c92b..2d499a2 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -94,18 +94,18 @@ public class Tournament implements Serializable { private void calcGameSchedule() { Collections.shuffle(participants); - for (int i = 0; i < (Math.log(participants.size()) / Math.log(2)); i++) { + for (int i = 0; i <= (Math.log(participants.size()) / Math.log(2)); i++) { List gameRound = new ArrayList<>(); if (i == 0) { for (int j = 0; j < participants.size() - 1; j += 2) { gameRound.add(new Game(participants.get(j), participants.get(j+1))); } - gameList.add(gameRound); } else { for (int j = 0; j < (participants.size() / Math.pow(2,i)); j++) { gameRound.add(new Game(null,null)); } } + gameList.add(gameRound); } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java index cbca67a..a53e43d 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java @@ -37,11 +37,17 @@ public class GameDecorator { } public String getParticipantOne() { - return game.getParticipant1().getName(); + if (game.getParticipant1() != null) { + return game.getParticipant1().getName(); + } + return "1"; } public String getParticipantTwo() { - return game.getParticipant2().getName(); + if (game.getParticipant2() != null) { + return game.getParticipant2().getName(); + } + return "2"; } public Place getLocation() {