• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet code compiles, will not run with local html file

 
James I Baker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an applet which compiles just fine (at least I get no errors), but when I try it out by putting it in a simple html document I simply cannot get the browser to run the applet. The simple applet is an example I got off the web (javaview.de), and it requires other classes, hence the non-standard import lines. The java code is given by:






Being a newbie it took me a little while to realize that I needed to "unzip" the jar file(s) (javaview.jar) in order to compile, but once I did that it compiled no problem.

With the tutorial that I'm using the idea is to look at the page source that the demo applet is embedded in and figure out what to do from there. The relevant part of the source is given by:


<applet code="vgp.tutor.firstApplet.MyApplet.class" codebase="../../../"
height="360" width="480" archive="jars/javaview.jar,jars/jvx.jar,jars/vgpapp.jar">

<param name="panel" value="Material">
</applet>


which I tried using in my html. No dice. I tried what feels like a million variants of the "code" and "codebase" variables. I've tried putting the MyApplet.class directly in the same directory as the html without the codebase or archive options. I've tried copying the jar files into a directory right below my html and .class file, and I still get and error when I run the html. I've tried making a vgp\tutor\firstApplet\ sub directory and putting MyApplet.class in there to no avail. I am getting a "ClassNotFoundException" error, which I understand to mean it cannot find the class file. But I feel like I have tried everything. Please if you can tell me *exactly* what I need to do in order for this to run. It seems easiest/best if I could have the .class file in the same directory as the html, but if you willing to tell me how to put the .class file in a sub directory (of the general html directory) I would be most pleased. Help me turn into ! For reference, (the)/(a usual) error is listed below:



load: class vgp.tutor.firstApplet.MyApplet.class not found.
java.lang.ClassNotFoundException: vgp.tutor.firstApplet.MyApplet.class
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: C:\Documents and Settings\James\Desktop\homeVSmark\classes\vgp\tutor\firstApplet\MyApplet\class.class (The system cannot find the path 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: vgp.tutor.firstApplet.MyApplet.class
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Remove the codebase attribute. You need to have a vgp\tutor\firstApplet directory hierarchy in the same directory the HTML file is in. In the "firstApplet" directory, put the MyApplet.class file. The value of the code attribute should be 'code="vgp.tutor.firstApplet.MyApplet" ', not 'code="vgp.tutor.firstApplet.MyApplet.class" '. Then it should work.
 
James I Baker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, Thanks Ulf! That worked like a charm, and it seems like the only iteration I didn't try. I was confused by the fact that I should have writen MyApplet.class simply as my MyApplet; in another, even simpler applet, the ".class" was included! Still a bit mysterious, but oh well.

I say the following purely for reference purposes (newbies like me searching this site/google): when relying on non-standard java packages (packages not included in the JDK) that come in a .jar file you must "unzip" the files via the command

jar xf jar-file [archived-file(s)]

for proper compilation AND ALSO include/reference them when calling the applet from the html file. for the html part you only need to include the .jar files in the html directory, and they are referenced via the "archive" attribute. For my example javaview.jar is the meaninful .jar file that is in the jar directory relative to where the html code text is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic