Tim Holloway wrote:First of all, Java does not have "pointers". Despite the fact that it has a "NullPointerException". Java works with references, and while you can use pointers to reference stuff, references themselves are not pointers in Java.
Tim Holloway wrote:
A multi-node list element with named "pointers", however, is not a good fit for Java. It could be done in several ways, including having the list node paired with a Map of named references, but that's a bit of overhead.
More commonly one would have the node associated with an object array and use integer value indexing. You could then use a Java Iterator, a for-each, or one of the newer language constructs to pass over the array's elements.
You could also associate a List node with a Collection. Which is what the Node-with-Map solution I iniitally suggested does.
Then again, you can do a lot with binary and trinary trees and simply use an existing library.
Carey Brown wrote:Instead of this, create a field 'hireDate' that is of type LocalDate and use these 3 parameters to construct the hireDate. There are lots of things that you can do with a LocalDate that are very difficult to do with just month/day/year, like compare two dates.
Carey Brown wrote:Just a reminder: it helps to periodically re-post your code in its current state so that we keep in sync with you and are not making comments on your prior posts that may no longer apply.
Carey Brown wrote:
Piet Souris wrote:if you have this in main
you will get a NullPointerException.
A simple way to prevent that is to initialize the ArrayList right away by using:
I tried this and unfortunately it didn't help.
But a thing to ask yourself is:
Why would a class called 'NewEmployee' that, as Campbell writes, should contain fields like name, adress, function, et cetera, also contain a List of currentEmplyees, and even a List of Lists of currentEmployees?
Piet Souris wrote:Not only that, but if the first constructor is used before the second, then currentEmployee is null.
Campbell Ritchie wrote:Why have you got a List<String> instead of individual fields? You should have fields called name, address, etc., and maybe Name, Address, classes to encapsulate those data.
What does the documentation for List#set() say? Have you got at least enough elements in the List before you call set() to accommodate the indices you are setting?
Stephan van Hulst wrote:When asking questions about an exception, please post the full stack trace.