I was trying the following code on NetBeans IDE 8.0:
public class ChoiceProgramDemo extends Applet implements ItemListener{
Label l1 = new Label();
Choice Product;
@Override
public void init() {
String[] ProductList = new String[4];
ProductList[0]="Pen";
ProductList[1]="Pencil";
ProductList[2]="Eraser";
ProductList[3]="NoteBook";
for(int i=0;i<ProductList.length;i++)
{
Product.insert(ProductList[i], i);
}
add(Product);
add(l1);
Product.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
int Selection;
Selection=Product.getSelectedIndex();
System.out.println(Selection);
}
}
But I am getting the following error:
java.lang.NullPointerException
at ChoiceProgramDemo.init(ChoiceProgramDemo.java:35)
at sun.applet.AppletPanel.run(AppletPanel.java:435)
at java.lang.Thread.run(Thread.java:745)
and Start: Applet not initialized
in the Applet Viewer.
I tried the same code on another PC on which it worked fine without any error. Is this any type of bug or an error?