我不明白为什么我会得到这个 NullPointerException。我开始尝试修复错误的许多不同外观的代码(并改进了您所看到的),但我无法弄清楚发生了什么。
非常感谢所有帮助:
final JComboBox modelName = null;
//Model ComboBoxModel
final DefaultComboBoxModel termModel = new DefaultComboBoxModel(new String[]{
"Choose One...", "Hypercom", "DejaVoo", "Nurit", "Verifone"});
...
// model drop-down
modelName.setModel(termModel); //getting nullPointerException on this line
modelName.addActionListener(this);
modelPanel.add(modelName);
...
@Override
public void actionPerformed(ActionEvent e) {
if ("Hypercom".equals(modelName.getSelectedItem())){
termName.setModel(hSpecModel);
} else if ("Deja Voo".equals(modelName.getSelectedItem())){
termName.setModel(dSpecModel);
} else if ("Nurit".equals(modelName.getSelectedItem())){
termName.setModel(nSpecModel);
} else if ("Verifone".equals(modelName.getSelectedItem())){
termName.setModel(vSpecModel);
} else {
termName.setModel(slctAbove);
}
}