I'm trying to write a program to create a media object, I created the Cassette class which inherits from Audio which inherits from Media. I'm getting a null pointer exception and I have been trying for hours to fix it but I have no idea why it's being thrown. I appreciate your help in advance, thank you.
In my application class I initiate the following:
static Media[] collection = new Media[100];
And later on in the code I try to create a new Cassette object but it gives me the said null pointer exception. The code I have is:
collection[collection[0].getNumItems()] = new Cassette(cTitle, cMajorArtist, cPlayingTime, cNumPlays, cNumGroupMembers, cGroupMembers, pArtist, cNumSongs, cSongs);
All of the items being passed into the Cassette are all user input data. It compiles fine but it's just when I run it that I get an error.
EDIT
Here is the numItems value in my media class.
static int numItems = 0;
And the method to return the number of items:
public int getNumItems()
{
return numItems;
}
Thanks.