[求助]初学者的小问题
import java.awt.*;import java.awt.event.*;
class WindowChoice extends Frame implements ItemListener,ActionListener
{
Choice choice;
TextField text;
TextArea area;
Button ad,del;
WindowChoice()
{
setLayout(new FlowLayout());
choice=new Choice();
text=new TextField(8);
area=new TextArea(8,25);
choice.add("音乐天地");
choice.add("无数天地");
choice.add("象棋乐园");
choice.add("交友聊天");
ad.addActionListener(this);
del.addActionListener(this);
text.addActionListener(this);
choice.addItemListener(this);
add(choice);
add(del);
add(ad);
add(area);
add(text);
setSize(200,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e)
{
String name=choice.getSelectedItem();
int index=choice.getSelectedIndex();
area.setText("\n"+index+":"+name);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ad||e.getSource()==text)
{
String name=text.getText();
choice.add(name);
choice.select(name);
area.append("\n列表添加"+name);
}
else if(e.getSource()==del)
{
area.append("\n列表删除"+choice.getSelectedItem());
choice.remove(choice.getSelectedIndex());
}
}
}
public class Example6
{
public static void main(String [] args)
{
new WindowChoice();
}
}
出现Exception in thread "main" java.lang.NullPointerException
at WindowChoice.<init>(Example6.java:19)
at Example6.main(Example6.java:59)
刚开始学习java各位高手能指点一下么,感激涕零!!!!