I accepted the input from the user and stored it in the variable "n". But, when I try to execute this code, I get java.lang.NullPointerException.
public class JavaApplication58 {
public static void main(String[] args) {
int a[] = null;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i < n; i++) {
a[i - 1] = i;
}
for (int i = 0; i < a.length; i++) {
System.out.println("" + a[i]);
}
}
}