This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Your getNextApplication method is in fact working. It returns whatever it finds, which is null. Now it would appear to be reading the elements of an array. Remember that an array of any reference type is implicitly filled with null references. If you don't explicitly fill the array with real references, you will eventually get one of the nulls back; when you get to the main method and try to something with that null the JVM says
Joined: Sep 11, 2007
Here is part of the missing loadApplication, sorry I thought I had copied it.
Rahul P Kumar
Joined: Sep 26, 2009
ok, you are saying first time. getNextApplication() returns an Application object initialized by parameterized constructor and does not initialize your apps array (not even a single value). i value at that time is 0. so apps is null. Avoid reassigning or workaround it.
Joined: Aug 31, 2009
On line 5 of class Software you create a new Application with the parameterless Constructor. So in this instance, the Application-array apps holds 4 instances of Application, created in your loadApplications()-method. On line 7 you call getNextApplication() on it, which returns the first entry of the array. Note, that this Application was created with the second constructor (new Application("Aquatint","1.1","Stick Software","","Mike","crocodiles","http://www.sticksoftware.com/","","");). Therefore it's apps-array is empty, because you don't call loadApplications() in that constructor.
So app on line 10 is null. Bingo.
One mistake, you make, is to reuse the variable app again and again. That way you call getNextApplication() always on a new instance of Application. Try this:
...but don't try it more than 4 times .
By the way: what is the intention to hold a list of Applications in Application-class? Shouldn't it rather be a class ApplicationPortfolio or so, to hold the Applications?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com