Forums Login/signup

Applet not initializing

+Pie Number of slices to send: Send
This is my first time writing a applet, and I'm getting an error that it is not initialized. I was pretty sure I did everything the book said to do, so I'm wondering if anyone could take a look at my code and see where I might have done something wrong. The CheckBoxApplet.java file does compile, but the applet does not initialize.
CheckBoxApplet.java

CheckBoxApplet.html

------------------
Thanks, Dianne
+Pie Number of slices to send: Send
Could you please send us the exact error message that is thrown in the "Applet Console" of the browser.
As a reminder, you have to put the applet in the same directory as the html (that contains the applet tag) resides.
Another cause may be the POLICY file.
Sabbir
+Pie Number of slices to send: Send
Yeah, I have the applet file and the html file in the same directory. Here is what the screen said:
[error]
C:\myjava\assignment2\problem1>javac CheckBoxApplet.java
C:\myjava\assignment2\problem1>appletViewer CheckBoxApplet.html
java.lang.ClassCastException: CheckBoxApplet
at sun.applet.AppletPanel.createApplet(AppletPanel.java:579)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:515)
at sun.applet.AppletPanel.run(AppletPanel.java:293)
at java.lang.Thread.run(Thread.java:484)
C:\myjava\assignment2\problem1>
[/error]
The applet window itself says "Start: applet not initialized."
In the Browser it doesn't say anything, it's just a grey box.
Also, I don't know what you mean by Policy file.
------------------
Thanks, Dianne
+Pie Number of slices to send: Send
Hi Dianne,
In order to create an applet you need to subclass 1 of 2 classes:
java.awt.Applet
or
javax.swing.JApplet
Which of these two have you subclassed?
Regards,
Manfred.
+Pie Number of slices to send: Send
What do you mean by subclass? I don't remember my teacher saying anything about a subclass.
------------------
Thanks, Dianne
+Pie Number of slices to send: Send
In order to run a class as an applet it must be declared public(as you have done) also it must subclass java.applet.Applet(you could also use the JApplet).
regards,
/Peter

Originally posted by Dianne Calhoun:
[B]This is my first time writing a applet, and I'm getting an error that it is not initialized. I was pretty sure I did everything the book said to do, so I'm wondering if anyone could take a look at my code and see where I might have done something wrong. The CheckBoxApplet.java file does compile, but the applet does not initialize.
CheckBoxApplet.java

CheckBoxApplet.html

[/B]


+Pie Number of slices to send: Send
Hi Dianne,
Looks like you have created an app instead of Applet. You may run your app using the "java app_name" command.
Sabbir
+Pie Number of slices to send: Send
Okay, I see now. I had to change the CheckBoxApplet extends JFrame to CheckBoxApplet extends JApplet. It works great now.
------------------
Thanks, Dianne
+Pie Number of slices to send: Send
I did what you said, and the applet still won't initialize. What am I doning wrong?
+Pie Number of slices to send: Send
> What am I doning wrong?

to start, posting to an 11-year-old post, with a number of replies already,
cuts down the number of people that will see your post.

much better to start your own topic (use the same subject if you like),
then post the code you've tried and explain the problem, or the steps to recreate the problem,
and I'm sure you'll get an answer in a reasonably quick time.

reply
reply
This thread has been viewed 19477 times.
Similar Threads
null pointer again!
Help i need help with borderlayout
TextAreaHandler
A confused new user of Java that needs some help
A confused new user of Java that needs some help
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 30, 2025 17:11:14.