"Exception in thread "main" java.lang.NullPointerException"
I'm trying to run a program that will, if all goes well, be able to take a year and return the title of an album released in that year. I've given it 6 albums already and I'm now trying to actually print a title. I've fixed a few pretty frustrating errors, but this is one I've not seen before. The error appears at line 21, but I'm not sure what it means. Can anyone help?


    package songselector;
    
    import java.util.Scanner;
    
    public class Main {
        public class Album
        {
    int year; String title;
    public Album () {
    this.year = 0; this.title = null;
            }
    public Album (int year, String title) {
    this.year = year; this.title = title;
         }
        }
    
       class CAKE {
    Album[] albums;
    public CAKE () {
    albums = new Album[6];
    albums[0].year = 1994; albums[0].title = "Motorcade Of Generosity";
    albums[1].year = 1996; albums[1].title = "Fashion Nugget";
    albums[2].year = 1998; albums[2].title = "Prolonging The Magic";
    albums[3].year = 2001; albums[3].title = "Comfort Eagle";
    albums[4].year = 2004; albums[4].title = "Pressure Chief";
    albums[5].year = 2011; albums[5].title = "Showroom of Compassion";
         }
    
    public void printAlbum (int y) {
    System.out.println (albums[y].title);
        }
    
        }
    
        public static void main(String[] args) {
            new Main().new CAKE().printAlbum (0);
        }
    }
"Exception in thread "main" java.lang.NullPointerException"
===

I'm trying to run a program that will, if all goes well, be able to take a year and return the title of an album released in that year. I've given it 6 albums already and I'm now trying to actually print a title. I've fixed a few pretty frustrating errors, but this is one I've not seen before. The error appears at line 21, but I'm not sure what it means. Can anyone help?


    package songselector;
    
    import java.util.Scanner;
    
    public class Main {
        public class Album
        {
    int year; String title;
    public Album () {
    this.year = 0; this.title = null;
            }
    public Album (int year, String title) {
    this.year = year; this.title = title;
         }
        }
    
       class CAKE {
    Album[] albums;
    public CAKE () {
    albums = new Album[6];
    albums[0].year = 1994; albums[0].title = "Motorcade Of Generosity";
    albums[1].year = 1996; albums[1].title = "Fashion Nugget";
    albums[2].year = 1998; albums[2].title = "Prolonging The Magic";
    albums[3].year = 2001; albums[3].title = "Comfort Eagle";
    albums[4].year = 2004; albums[4].title = "Pressure Chief";
    albums[5].year = 2011; albums[5].title = "Showroom of Compassion";
         }
    
    public void printAlbum (int y) {
    System.out.println (albums[y].title);
        }
    
        }
    
        public static void main(String[] args) {
            new Main().new CAKE().printAlbum (0);
        }
    }