+ 1
[Solved] Help me please. Where is error in my code?
Exception inthread "main" java.lang.NullPointerException at Program.main(Program.java:10) https://code.sololearn.com/cozBcsy3hlSx/?ref=app
2 Answers
+ 7
Change line 12 to:
Books[] meBooks = {new Books(), new Books(), new Books()};
Or you could leave it, but you need to make sure that you instantiate all of the objects in the array before trying to access their members/fields.
for(int i = 0; i < 3; ++i) {
meBooks[i] = new Books();
}
or
meBooks[0] = new Books();
meBooks[1] = new Books();
meBooks[2] = new Books();
+ 2
I understand. I created the array, but not put items to it. Thanx ChaoticDawg.