From 2855b634c98e8e80a8b4cb75b8e623d57217fd6d Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 24 Apr 2021 16:20:59 +0200 Subject: [PATCH] Fix NullPointerException when arguments are incorrects --- src/battleship/Main.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/battleship/Main.java b/src/battleship/Main.java index be3ae37..0e963d4 100644 --- a/src/battleship/Main.java +++ b/src/battleship/Main.java @@ -12,6 +12,7 @@ import battleship.view.Window; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.NoSuchElementException; public class Main { @@ -48,7 +49,10 @@ public class Main { } } } - game = new Game(players); + if(players[0] != null && players[1] != null) { + game = new Game(players); + } else + throw new IllegalArgumentException("Arguments incorrects: " + Arrays.toString(args)); if(args.length >= 3) { // arguments > 3 ignorés if(args[2].equalsIgnoreCase("nogui"))