Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Simple problem with Applet in HTML(why doesn't my applet built in Eclipse (Mac) run in HTML?)
Simple problem with Applet in HTML [message #778398] Thu, 12 January 2012 13:37 Go to next message
Chris Crawford is currently offline Chris Crawford
Messages: 7
Registered: January 2012
Junior Member
This is a such a simple problem that I'm shocked by my inability to solve it, but after five days of messing with it, scouring the web, re-reading tutorials, and searching previously-asked similar questions here, I still haven't figured it out. I'm going to present it in great detail to make sure that I've explained it completely.

1. Context: I'm using Eclipse Indigo Service Release 1 on a Mac with OS 10.7.2 with 8 GB RAM.

2. Here's the Java code:

package helloYellow;


import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;

public class HelloWorld extends JApplet {
private static final long serialVersionUID=1L;
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}

3. When I run this as an applet inside Eclipse, it works perfectly.

4. Here's the HTML page that calls the applet:
(I'm not permitted to use links until I have posted more than 5 messages, so I am replacing the HTML delimiters with curly braces)


{body}
Upper bracket text{br}
{applet code="hellowYellow/HelloWorld.class" width="300" height="150"}{/applet}{br}
Lower bracket text{br}
{/body}
{/html}


4. Apparently I'm not allowed to include images in my postings yet, so I'll describe the page as it appears in Safari: it shows shows "Upper bracket text" and "Lower bracket text". Between them is a box outline that says "Error. Click for details".


5. When I click on "Click for details", I get an error message stating that the application failed to run, presenting me with a button permitting me to "click for details". When I click that button, I get a Java Console window with the following contents:

Java Plug-in 1.6.0_29
Using JRE version 1.6.0_29-b11-402-11M3527 Java HotSpot(TM) 64-Bit Server VM
User home directory = /Users/chris
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


load: class hellowYellow/HelloWorld.class not found.
java.lang.ClassNotFoundException: hellowYellow.HelloWorld.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: hellowYellow.HelloWorld.class
load: class hellowYellow/HelloWorld.class not found.
java.lang.ClassNotFoundException: hellowYellow.HelloWorld.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: hellowYellow.HelloWorld.class

6. Here is the folder containing the HTML page has these contents:

HelloWorld.class
HelloWord$1.class
helloYellow:
...HelloWorld.class
...HelloWord$1.class
java.policy.applet
Java2.html


Note that I used some overkill in including the class files twice: once by themselves and once inside the folder "helloYellow". I just wanted to make absolutely certain that they were accessible to the HTML file, no matter what assumptions it made as to their locations.

Can anybody figure out where I'm going wrong here?
Re: Simple problem with Applet in HTML [message #778525 is a reply to message #778398] Fri, 13 January 2012 00:31 Go to previous messageGo to next message
Tim Bennett is currently offline Tim Bennett
Messages: 10
Registered: January 2012
Junior Member
Not sure if it's just a typing mistake, but down where you show your folder listing, you have "HelloWorld.class" and "HelloWord$1.class" (the second 'World' has no 'l'...)

Also, in your HTML code, you have spelled the package name "hellowYellow" instead of "helloYellow" (There's an extra 'w' in the first one...)

Another thing: When you're listing your 'code' parameter in your 'applet' tag, don't forget that you have made a Java package. How do you step inside a Java package? With a '.' (dot) operator, not a '/' (forward slash) or '\' (backslash).

Try code="helloYellow.HelloWorld.class". You should be able to get rid of the two Java class files in the main directory (outside the package).

See if that helps.
Re: Simple problem with Applet in HTML [message #778665 is a reply to message #778525] Fri, 13 January 2012 11:20 Go to previous message
Chris Crawford is currently offline Chris Crawford
Messages: 7
Registered: January 2012
Junior Member
I nearly fell out of my chair laughing at my own stupidity when I saw the spelling error you pointed out. I fixed it and, of course, now the thing works perfectly. It's funny, in a sick sort of way, how we can look at the same mistake 20 times and never notice it.

Thanks so much for catching this. I'm now off and stumbling again, making forward progress, and I won't darken this forum's door with another problem until I've carefully checked my spelling!
Previous Topic:Using Internal ASTNode(not DOM's) 's "bits" field...
Next Topic:CodePro Analytix Results Inconsistency
Goto Forum:
  


Current Time: Wed Jul 23 20:35:36 EDT 2014

Powered by FUDForum. Page generated in 0.07881 seconds