這是一個硬件問題。我不斷收到屏幕下面的錯誤與我的,如果(我== 3)語句...試圖用java創建一個開關
「異常線程 「AWT-EventQueue的-1」 顯示java.lang.NullPointerException 在ui.panels.ChoicePanel $ 1 .itemStateChanged(ChoicePanel.java:31)「
...有人能指點我正確的方向嗎?這是我的代碼。謝謝你的時間。
package ui.panels;
import java.awt.Choice;
import java.awt.Panel;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import model.Model;
import interfaces.Resettable;
public class ChoicePanel extends Panel implements Resettable{
public int i = 0;
/**
*
*/
private static final long serialVersionUID = 1L;
Model model;
Choice selection;
public ChoicePanel(Model mdl) {
selection = new Choice();
for (String msg : Model.selections) {
selection.add(msg);
}
selection.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(i==3) {//drop down clicked three times)
System.out.println("PING");
}else{
model.setMessage(selection.getSelectedItem());
//this line is what sends a value to shape that is drawn on screen
//NOT line 36 of GUIDemo.java
//
model.setCurrentShapeType(selection.getSelectedItem());
model.repaint();
++i;
}
}
});
this.add(selection);
}
public void resetComponents() {
//this resets the drop down list selection array to the first choice on the list
selection.select(0);
//this sets selected item in the selection array set in the above line
model.setMessage(selection.getSelectedItem());
//model.repaint();
}
}
代碼中的哪一行是第31行(來自錯誤消息的行)? – 2011-03-23 22:35:01