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.
I thought I had the sort routine worked out, but now it is throwing a NullPointerException whenever I add an item to the array, then try to sort it. The array is loaded with 23 items, I add a 24th, then do the sort to put the array into sequence by Software name, that is when it crashes. The method involved is addApplication.
Ok, but if I declare an array large enough to hold what I have, plus allow for expansion, then I'm going to have null elements. How do I handle this situation? From what I've learned, once I've declared an array to be  I can't increase it to  to add another entry without recompiling the entire application.
Is there a reason you're not using a List, ArrayList or LinkedList? Those are dynamically sized so you'll be able to add and delete items without caring about having enough space or comparing null values....
When you do things right, people won't be sure you've done anything at all.
Mike Lipay wrote:Ok, but if I declare an array large enough to hold what I have, plus allow for expansion, then I'm going to have null elements. How do I handle this situation?
You have two options... (1) you can use the version of sort() that allows you to sort a range in the array -- meaning only sort the area in the array that you are actually using. or (2) you can use the version of sort() that takes a comparator. A comparator allows either of the two elements, to be compared, to be null (well, you still have to write it so, but it is possible).