I want to create an array of a type which I create.
Here’s my problem:
public class MyFile
{
int page_no=23;
Page[] pages_in_file;
MyFile()
{
pages_in_file=new Page[page_no];
}
}
And Java gives error when debug comes to Page[] part and it does not even entes Page’s constructor.
Page Class is this:
public class Page
{
String data=null;
String contain=null;
Page()
{
data = new String();
contain = new String();
}
}
Error says : “Source not found” and gives this NullPointerException when I try to access an element in the array.
I guess I don’t see an obvious error but i appreciate any help. Thanks
Java only allocates the memory for your classes, it does not run the constructors when initialising the array. At a minimum, you will need to add: