Working with JList

Hi,

I'm trying to do a categorization in my application.

Ideally, I have a list of (String) season's name and a list of Recipe objects. What I'm trying to do is that, each time I select a season name, I want the application to show all the Recipes that matched the season name.

Below is what I've written, but somehow it's giving meNullPointerException I dont understand it cos it was working the first time.

publicvoid jSeasonList_valueChanged(ListSelectionEvent e){

try{

resultList.removeAllElements();//clear result list

//get selected season name

String aSeason = (String) seasonList.get(jSeasonList.getSelectedIndex());

for (int i = 1; i < recipeList.size(); i++){

//go through recipe list

Recipe aRecipe = (Recipe) recipeList.get(i);

if (aRecipe.getSeason().equals(aSeason))

//if selected season match the one on the recipe, add to result

resultList.add(aRecipe);

}

jResultList.setListData(resultList);//update list

}

catch(NullPointerException ne){

System.out.println("Unknown Error!?");

}

}

Any helps n suggestions would be much appreciated!

[1829 byte] By [CUIDAa] at [2007-11-26 19:30:10]
# 1

"public class NullPointerException

extends RuntimeException

Thrown when an application attempts to use null in a case where an object is required. These include:

Calling the instance method of a null object.

Accessing or modifying the field of a null object.

Taking the length of null as if it were an array.

Accessing or modifying the slots of null as if it were an array.

Throwing null as if it were a Throwable value.

Applications should throw instances of this class to indicate other illegal uses of the null object. "

Im trying to fit it in one of these case but still cant identify where the problem is coming from... :s

CUIDAa at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...
# 2

What about posting the NPE and marking the line the compiler tells you causing the NPE?

Btw., this forum is about Collections, not Swing, which can be found here: http://forum.java.sun.com/forum.jspa?forumID=57

But it seems, you are having a more beginner's like problem, which should go here: http://forum.java.sun.com/forum.jspa?forumID=31

stefan.schulza at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...
# 3
don't worry i've sorted it out myself now...silly mistake with the .equal method.and yes im a beginner, n proud of it!
CUIDAa at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...
# 4
I did not belittle you as beginner but classified the problem as such, which is the base for choosing the right forum most likely to give you the help you need.
stefan.schulza at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...
# 5
respect!I now have a problem with StringTokenizer together with File I/O...where should this go under?
CUIDAa at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...
# 6
Not this one.
DrClapa at 2007-7-9 21:59:18 > top of Java-index,Core,Core APIs...