Hi, I'm triying to fill an array of class "Months"
All I'm triying to fill is something like this: "array[position].atribute"
Every Month must have name and days;
I get java.lang.NullPointerException , I don't understand why, I tryed using getter and setter but I don't fix it, I don't understand what's wrong, I don't get any compilation errors.
Thank you.
import java.util.Scanner; public class Arrays { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); Months [] array = new Months[12]; for(int i=0; i<array.length; i++){ System.out.println("Introduzca el nombre del mes:\t"+(i+1)); array[1].name = keyboard.nextLine(); System.out.println("Introduzca los días que tiene el mes:\t"); array[i].days = keyboard.nextInt(); } keyboard.close(); for(int i=0; i<array.length; i++){ System.out.println(array[0].name); System.out.println(array[0].days); } } } class Months { String name; int days; }