jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Applet Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet Help" Watch "Applet Help" New topic

Applet Help

Pispa Lupa

Joined: Aug 04, 2003
Posts: 5
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?
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
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
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

Joined: Aug 04, 2003
Posts: 5
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.
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();

// 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

// Adding controls for Customer Name

// Adding controls for Customer Sex

// Adding controls for Customer Age

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

- Are you on an X/Windows-based system (Linux, Solaris) and your display is not set?
- Can you run non-applet graphical programs?

[Jess in Action][AskingGoodQuestions]
Pispa Lupa

Joined: Aug 04, 2003
Posts: 5
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!
Have you checked out Aspose?
subject: Applet Help
It's not a secret anymore!