What's wrong with this incredibly simple applet???

K

Karen Jenkins

I know this is supposed to be extremely simple but I have toiled for hours
over this and just cannot see what I am doing wrong. Can anyone point out
my mistake?

The environment is Java 6 Update 10 b25 on Windows Vista. I have a folder
D:\Test and in it I have 2 files namely applet.jar and applet.html. The
applet.jar contains one class namely MyApplet. The contents of the HTML
file are:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<applet code="MyApplet" archive="applet.jar" width="492"
height="280">
</applet>
</body>
</html>

As I said, all very simple. Now I am not concerned at this point what the
applet actually does - I just can't even get it to find it. When I run/open
the HTML file in any browser I get the following exception:

load: class MyApplet not found.
java.lang.ClassNotFoundException: MyApplet
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown
Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: D:\Test\MyApplet.class (The system
cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown
Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: MyApplet

Why doesn't this work? I have tried adding ".class" the the code tag but
then it looks for MyApplet.class.class and I have tried putting the full
path to the applet.jar but the result is the same.

Anyone?

Cheers,

Karen (tearing her hair out!)
 
A

Andrew Thompson

I know this is supposed to be extremely simple ..

Applets are never very simple.

Why do you need an applet (as opposed to a frame)?
..but I have toiled for hours
over this and just cannot see what I am doing wrong.  Can anyone point out
my mistake?

What is the exact code of MyApplet?

Is it in a package?

Where in the applet.jar is the class located?

Did you check that last answer?
 
K

Karen Jenkins

Andrew Thompson said:
On Jun 21, 8:44 pm, "Karen Jenkins" <[email protected]> wrote:

Thanks Andrew for trying to help.
Applets are never very simple.

I see.
Why do you need an applet (as opposed to a frame)?

My boss needs me to do some work with applets so I am just trying to get the
most basic example to work.
What is the exact code of MyApplet?

Unfortunately I am not allowed to post this but it shouldn't make any
difference in terms of just starting the applet itself should it? I'll
worry about getting the actual applet working when I have figured out how to
start it.
Is it in a package?
No.

Where in the applet.jar is the class located?

Just in the root directory.
Did you check that last answer?

Yes, I renamed applet.jar to applet.zip and checked. It contains one
object: MyApplet.class in the root directory.

Any further ideas?

Karen
 
A

Andrew Thompson

Unfortunately I am not allowed to post this but it shouldn't make any
difference in terms of just starting the applet itself should it?  

It will if the class is actually declared as
Myapplet rather than MyApplet (or possibly
other reasons).
Any further ideas?

Post an SSCCE.
<http://pscode.org/sscce.html>

Note that I am *not* *asking* for 'your code',
but an SSCCE that fails in the way you describe.
 
R

Roedy Green

Exception: java.lang.ClassNotFoundException: MyApplet

1. always put your classes in a package.

2. examine your jar file with jarlook.html to make sure all the pieces
you need are in there and properly named.

see http://mindprod.com/jgloss/products1.html#JARLOOK

3. Use winzip to extract the manifest and have a look at it. It
should have a main-class entry. See
http://mindprod.com/jgloss/jar.html

4. download one of my applets, something simply like the insult
generator. Look at the structure of its jars, source code, build
files etc, and slavishly copy the structure.

see http://mindprod.com/applet/applets.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top