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

Discussion in 'Java' started by Karen Jenkins, Jun 21, 2008.

  1. 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!)
     
    Karen Jenkins, Jun 21, 2008
    #1
    1. Advertising

  2. On Jun 21, 8:44 pm, "Karen Jenkins" <> wrote:
    > 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?

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 21, 2008
    #2
    1. Advertising

  3. "Andrew Thompson" <> wrote in message
    news:...
    > On Jun 21, 8:44 pm, "Karen Jenkins" <> wrote:


    Thanks Andrew for trying to help.

    >> I know this is supposed to be extremely simple ..

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

    >>..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?


    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
     
    Karen Jenkins, Jun 21, 2008
    #3
  4. On Jun 21, 10:48 pm, "Karen Jenkins" <> wrote:
    > "Andrew Thompson" <> wrote in message

    ...
    > > 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?  


    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.

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 21, 2008
    #4
  5. Karen Jenkins

    Roedy Green Guest

    On Sat, 21 Jun 2008 20:44:39 +1000, "Karen Jenkins"
    <> wrote, quoted or indirectly quoted someone who
    said :

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

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 21, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    2
    Views:
    321
    aaaaa
    Sep 17, 2004
  2. Mabden
    Replies:
    5
    Views:
    522
    Ioannis Vranos
    Oct 27, 2004
  3. drife
    Replies:
    9
    Views:
    449
    Robert Kern
    Jan 29, 2005
  4. Mufasa
    Replies:
    1
    Views:
    367
    Eliyahu Goldin
    May 20, 2008
  5. Aahz
    Replies:
    2
    Views:
    303
Loading...

Share This Page