Fix NullPointerException when arguments are incorrects

This commit is contained in:
Quentin Legot 2021-04-24 16:20:59 +02:00
parent c43b200888
commit 2855b634c9

View File

@ -12,6 +12,7 @@ import battleship.view.Window;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
public class Main { 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) { if(args.length >= 3) {
// arguments > 3 ignorés // arguments > 3 ignorés
if(args[2].equalsIgnoreCase("nogui")) if(args[2].equalsIgnoreCase("nogui"))