日期:2014-05-20  浏览次数:20822 次

大家帮我看看这段程序怎么了!谢谢!
import   java.awt.*;  
import   java.io.*;  
import   javax.swing.*;

public   class   VideoCD   extends   JApplet{
JPanel   panelObject;
int   stopCount;
int   startCount;

JLabel   labelVideoCDNo,labelVideoCDName,labelGenre,labelArtist,labelCount;
JTextField   textVideoCDNo,textVideoCDName,textArtist;
JComboBox   comboGenre;

public   void   init(){
panelObject   =   new   JPanel();
getContentPane().add(panelObject);

labelVideoCDNo   =   new   JLabel( "VIdeo   CD   Number ");
labelVideoCDName   =   new   JLabel( "Name ");
labelGenre   =   new   JLabel( "Package ");
labelGenre   =   new   JLabel( "Artist ");
labelCount   =   new   JLabel();

textVideoCDNo   =   new   JTextField(15);
textVideoCDName   =   new   JTextField(30);
textArtist   =   new   JTextField(30);

String   genres[]   =   { "Rock ", "Pop ", "Classical ", "Rap "};
comboGenre   =   new   JComboBox(genres);
panelObject.add(labelVideoCDNo);
panelObject.add(textVideoCDNo);
panelObject.add(labelVideoCDName);
panelObject.add(textVideoCDName);
panelObject.add(labelGenre);
panelObject.add(comboGenre);
panelObject.add(labelArtist);
panelObject.add(textArtist);
panelObject.add(labelCount);
startCount++;
String   count   =   "Start   count   is "+   startCount   +   "Stop   count   is "   +   stopCount;
labelCount.setText(count);
stopCount++;
String   count1   =   "Stop   Count   is   "   +   stopCount   +   "Start   count   is "   +   startCount;
labelCount.setText(count1);
}

}


运行的时候老是报下面这段错:
java.lang.NullPointerException
at   java.awt.Container.addImpl(Unknown   Source)
at   java.awt.Container.add(Unknown   Source)
at   VideoCD.init(VideoCD.java:36)
at   sun.applet.AppletPanel.run(Unknown   Source)
at   java.lang.Thread.run(Unknown   Source)

------解决方案--------------------
labelArtist = new JLabel( "Whatever ");