This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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(
at java.awt.Container.add(
at Customer1.init(
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 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: 24193

- 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!
I agree. Here's the link:
subject: Applet Help
It's not a secret anymore!