wallaceoc80
Programmer
In a MIDlet I'm writing I am using some ChoiceGroups. At the moment for each choiecgroup I have a separate but very similar method that creates and displays the choicegroup.
I'm trying to write one generic method that takes a ChoiceGroup as a paramater and creates and displays the ChoiceGroup. However, when I try to access the ChoiceGroup later i keep getting a null pointer exception.
Here is some code:
Does anybody know why I'm getting the error. Is it that ChoiceGroups are passed by value rather than reference?
Thanks for the help,
Wallace
I'm trying to write one generic method that takes a ChoiceGroup as a paramater and creates and displays the ChoiceGroup. However, when I try to access the ChoiceGroup later i keep getting a null pointer exception.
Here is some code:
Code:
public void categoryChoices(ChoiceGroup cg, String [] catChoices, String strCurrentMenu)
{
cg = new ChoiceGroup("Star Rating", Choice.MULTIPLE, catChoices, null);
try
{ Vector temp = (Vector)vCategoryFlags.elementAt(currentCat);
boolean [] tmp = (boolean [])temp.elementAt(currentSubCat);
if(tmp.length == cg.size())
{
cg.setSelectedFlags(tmp);
}
}
catch(ArrayIndexOutOfBoundsException ex)
{
System.out.println(ex.toString());
}
displayForm = new Form("Make Choice");
displayForm.append(cg);
displayForm.addCommand(backCommand);
displayForm.setCommandListener(this);
display.setCurrent(displayForm);
currentMenu = strCurrentMenu;
}
...
...
...
switch(currentSubCat)
{
case 0: categoryChoices(cgHotelChoices, hotelChoices, "hotels"); break;
case 1: categoryChoices(cgBbChoices, bbChoices, "bandb" ); break;
}
Does anybody know why I'm getting the error. Is it that ChoiceGroups are passed by value rather than reference?
Thanks for the help,
Wallace