+ 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

17th Dec 2017, 9:53 AM
J S Morgan
J S Morgan - avatar
2 Respostas
+ 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();
17th Dec 2017, 10:08 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I understand. I created the array, but not put items to it. Thanx ChaoticDawg.
17th Dec 2017, 10:09 AM
J S Morgan
J S Morgan - avatar