This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This problem is starting to drive me insane. I'm sure it must be something really simple, but I just can't seem to find out where the problem is. I initialize a population from the main() function, containing a collection of individuals with:
I then try to access the attributes of one of those Individuals to test if the program works with:
But it does not work, the compiler throws a null pointer exception. Any help anyone can provide will be gratefully accepted.
In your Population class you're creating an Individual array, but you aren't putting anything in it. When an array of some sort of object is created it just contains nulls everywhere. So when you call robots.getPositionX() ...robots is null.
You need to create the Individual objects and put them in the array.