• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet Help

 
Pispa Lupa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,
I am trying to run some applets that I wrote using appletviewer but I'm getting the following error although I have the current JVM and JRE installed. Any help?
java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:336)
at java.awt.Container.add(Container.java:223)
at Customer1.init(Customer1.java:49)
at sun.applet.AppletPanel.run(AppletPanel.java:340)
at java.lang.Thread.run(Thread.java:479)
I get this error when I'm trying to run even the simplest applet there is.
Thanks for your help.
P.S. If you'd like for me to paste the html code I wrote, please let me know
Pispa
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your own Customer1 init() method, line 49. Looks like you are trying to add a component that probably hasn't been initialized. If that doesn't help, post the code from your Customer1.java file.
 
Pispa Lupa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Chad,
Thanks for the quick reply. I looked at the code but I can't seem to find the mistake. Keep in mind that this is also happening when I'm running a simple Hello world applet. Anyway, here is the code and I appreciate the help.
Pispa.
import javax.swing.*;
import java.awt.Graphics;
public class Customer1 extends JApplet {
// Variable for the panel
JPanel panelObject;

// Variables of labels
JLabel labelCustNo;
JLabel labelCustName;
JLabel labelCustSex;
JLabel labelCustAge;

// Variables for data entry controls
JTextField textCustNo;
JTextField textCustName;
JComboBox comboCustSex;
JTextField textCustAge;

public void init() {
// Add apprropriate controls to the frame
// Create panel
panelObject = new JPanel();
getContentPane().add(panelObject);

// Create and add the appropriate controls
// Initializing labels
labelCustNo = new JLabel("Customer Number");
labelCustName = new JLabel(" Name");
labelCustNo = new JLabel("Sex");
labelCustNo = new JLabel("Age");

// Initializing textfield
textCustNo = new JTextField(15);
textCustName = new JTextField(30);
textCustAge = new JTextField(2);
String Sex[] = { "Male", "Female" };
comboCustSex = new JComboBox(Sex);

// Adding controls for Customer Number
panelObject.add(labelCustNo);
panelObject.add(textCustNo);

// Adding controls for Customer Name
panelObject.add(labelCustName);
panelObject.add(textCustName);

// Adding controls for Customer Sex
panelObject.add(labelCustSex);
panelObject.add(comboCustSex);

// Adding controls for Customer Age
panelObject.add(labelCustAge);
panelObject.add(textCustAge);

}
}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Are you on an X/Windows-based system (Linux, Solaris) and your display is not set?
- Can you run non-applet graphical programs?
 
Pispa Lupa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,
I found the errors and fixed them. Lines 28-31
labelCustNo = new JLabel("Customer Number");
labelCustName = new JLabel(" Name");
labelCustSex = new JLabel("Sex");
labelCustAge = new JLabel("Age");
I did not name labelCustSex and labelCustAge correctlty the first time. Sorry about that and thanks for the help!
Lupa.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic