5 Replies Latest reply: May 9, 2012 8:37 PM by 935964 RSS

    Class Not Found Exception - applet won't run anywhere outside of IDE

    935964
      I have an applet that runs perfectly in the netbeans IDE, but won't run from command prompt (I'm using windows) or from a browser. I've been banging my head against the wall for a few days on this one. Here's the HTML I'm using:

      <applet width="400" height="525" code="musicapplet.class" archive="crypticgraffiti.jar">
      <param name="bgcolor" value="ffffff"> <param name="fontcolor" value="000000">
      </param> </param> Your browser is not Java enabled. </applet>


      Here is the structure of the jar file's contents:

      META-INF/
      META-INF/MANIFEST.MF
      com/
      com/crypticgraffiti/
      com/crypticgraffiti/music/musicapplet
      com/crypticgraffiti/music/GetNotes.class
      com/crypticgraffiti/music/InstList.class
      com/crypticgraffiti/music/Mode.class
      com/crypticgraffiti/music/MusicCreator.class
      com/crypticgraffiti/music/OctaveTransformer.class
      com/crypticgraffiti/music/Phrase.class
      musicapplet/MusicApplet$playerThread.class
      musicapplet/MusicApplet.class

      (Musicapplet.class is the main class)

      When I attempt to run from command prompt, I get:

      "Error: Could not find or load main class crypticgraffiti.MusicApplet"

      When I attempt to load via html:

      "basic: load: class musicapplet.class not found.
      load: class musicapplet.class not found.
      java.lang.ClassNotFoundException: musicapplet.class
           at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
           at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
           at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
           at sun.plugin2.applet.Plugin2ClassLoader.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)
      Exception: java.lang.ClassNotFoundException: musicapplet.class
      security: Accessing keys and certificate in Mozilla user profile: null"

      I have tried every possible variation for the 'code' element of the applet tag (package.mainclass.class, mainclass, mainclass.class, etc). I have also tried compiling with JDK 1.6 and this didn't change anything. I've tried clearing out the cache of temporary files using the java control panel settings, and have verified that my browser can run other applets using JRE 6 and 7.

      I've tried some different ways of distributing the applet, also: putting all the class files in the folder with the html file, putting the classes in a source folder in the same folder as the html file, and finally putting a jar in the same folder as the html file (which really seems the simplest).

      Any help at all would be most appreciated! This applet is a very cool and original music creating app that draws heavily on the JFugue API. It's a shame that I can't get it online for people to play with!
        • 1. Re: Class Not Found Exception - applet won't run anywhere outside of IDE
          Nitin Khare
          Cryptic Graffiti wrote:

          Here is the structure of the jar file's contents:

          META-INF/
          META-INF/MANIFEST.MF
          com/
          com/crypticgraffiti/
          com/crypticgraffiti/music/musicapplet
          com/crypticgraffiti/music/GetNotes.class
          com/crypticgraffiti/music/InstList.class
          com/crypticgraffiti/music/Mode.class
          com/crypticgraffiti/music/MusicCreator.class
          com/crypticgraffiti/music/OctaveTransformer.class
          com/crypticgraffiti/music/Phrase.class
          musicapplet/MusicApplet$playerThread.class
          musicapplet/MusicApplet.class

          (Musicapplet.class is the main class)
          Please note that class names are case sensitive so "MusicApplet" is not same as "Musicapplet" or "musicapplet". Your applet tag should have fully qualified class name (without quotes) and should look like this:

          <applet width=400 height=525 code=musicapplet.MusicApplet archive="crypticgraffiti.jar">
          ..
          ..
          </applet>

          The JAR should be in the same directory as your HTML file. While launching from command line, you can also check if your JAR file is getting included in classpath.


          Thanks,
          Nitin
          • 2. Re: Class Not Found Exception - applet won't run anywhere outside of IDE
            baftos
            So many things that are surely wrong or could be wrong...
            1. </param> is not part of the applet tag specification.
            2. The fully qualified class name must be used (packagename.ClassName).
            3. The class name is CaseSensitive.
            4. The class name does not need the ".class" suffix.
            5. Applets cannot be run outside of the browser from the command line.

            If the above does not help, please tell us the exact URL you use and the structure of what is on the web server (HTML page, jar location).
            • 3. Re: Class Not Found Exception - applet won't run anywhere outside of IDE
              935964
              Thank you, baftos and Nitin Khare! It was the case sensitive thing. Surprised I didn't notice that mentioned in any documentation or programming books. Thanks again!
              • 4. Re: Class Not Found Exception - applet won't run anywhere outside of IDE
                EJP
                The Java Language Specification says that Java is case sensitive. It's no secret.
                • 5. Re: Class Not Found Exception - applet won't run anywhere outside of IDE
                  935964
                  Well, yeah I knew that. I guess I was just thinking of the applet tag purely in HTML terms for some reason. Also, I've only been programming java for about three weeks...had been doing VB.NET before, so the case-sensitivity still gets me sometimes!