This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
Hey, Asha. This problem is one of the reasons I suggest using an editor with syntax highlighting as it makes mistakes like this slightly more obvious. What has happened here is this:
You have created a field in the Weekdays class called dayNamesAL on line 7, but you have also created a local variable called dayNamesAL on line 17 by placing a type in front of the variables name. Now, Java does allow this, but unfortunately, the rest of the code in your constructor is initializing this local variable and not the field, so when findDayAL is called, the dayNamesAL field is still uninitialized resulting in the NullPointerException.
To correct this, simply remove the type information from in front of the variable name on line 17. That line should look like this.
OP, what you're doing here is really simple... don't you feel a little bit bad taking 80 lines of code? Think of someone trying to maintain it!
You can start by eliminating your constructor and initializing the fields in place, then check out the indexOf method on ArrayList, so you'll end up with something like:
True, in theory the findDayA method isn't quite as efficient as yours since it'll create a new ArrayList each time, but you should write the simplest code that will work, rather than trying to solve a performance problem that doesn't actually exist ("premature optimization").