public class Main { public static int[] array; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int max = Integer.MIN_VALUE; int n = Integer.parseInt(sc.nextLine()); for (int i = 0; i < n; i++) { array[i] = Integer.parseInt(sc.nextLine()); if (array[i] > max) max = array[i]; } System.out.println(max); } } Exception in thread "main" java.lang.NullPointerException: Cannot store to int array because "Studi.Main.array" is null at Studi.Main.main(Main.java:15)