Originally Posted by
Jeremy720
Hello. I'm trying to populate a combo box using an MVC model, and am using either serialization, or a database based on the users preference. I'm not sure exactly what's going on, but it's a visibility issue between the listener, controller, and interface classes upon instantiation...
FROM THE LISTENER:
public Listener(Controller pc)
{
this.pc = pc;
foodChoices = pc.getFoodChoices
(categoryList.getSelectedItem().toString());
foodList = new JComboBox(foodChoices);
...
con.add(foodList);
...
}
FROM THE CONTROLLER:
public class Controller()
{
public static void main(String[] args)
{
Controller app = newController();
app.initialize();
}
public void initialize()
{
pl = new Listener(this);
dir = System.getProperty("user.dir");
appPath = dir.substring(0,dir.lastIndexOf('\\'));
while (check)
{
String daoAccess = JOptionPane.showInputDialog(null,
"Enter S to read/write to text file, D to read/write to database");
if (daoAccess != null)
{
if (daoAccess.equalsIgnoreCase("d"))
{
sd = new SQLDAO(this);
pl = new Listener(this);
check = false;
}
else if (daoAccess.equalsIgnoreCase("s"))
{
dir = System.getProperty("user.dir");
appPath = dir.substring(0,dir.lastIndexOf('\\'));
pl = new ProteinListener(this);
sd = new SerialDAO(appPath);
check = false;
}
else if (daoAccess == "")
{
System.out.println("You must enter a data access type");
check = true;
}
else
{
Utility3.errorMessage("Invalid entry");
check = true;
}
}
else
break;
}
}
(METHOD FOR READING DATABASE/FILE FOR COMBO BOX POPULATION):
public String[] getFoodChoices(String category)
{
return dao.getFoodChoices(category);
}
}
RUNTIME ERROR:
NullPointerException
@ Controller.getFoodChoices
@ Listener.<init>
@ Controller.initialize
@ Controller.main
Any ideas?
Thanks so much. this is a personal project I'm doing over the summer.