Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ChoiceGroup - pass by reference??

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
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:
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
 
// I use the following code to store boolean array in a objet
import java.util.*;
class v
{
public static void main(String args[])
{
Vector vect = new Vector();
boolean bo[] = new boolean[4];
bo[3] = true;
MyBooleanArr myBooleanArrObj = new MyBooleanArr(bo);
vect.add(myBooleanArrObj);
//
// get back the MyBooleanArr from vector
MyBooleanArr tempMyBooleanArr = (MyBooleanArr)(vect.get(0));
boolean tempArray[] = tempMyBooleanArr.getArray();
for (int i=0;i<4;i++)
System.out.println(tempArray);
}
}
class MyBooleanArr
{
boolean myArr[];
public MyBooleanArr(boolean temp[])
{
myArr = temp;
}
public boolean[] getArray()
{
return myArr;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top