aspose file tools*
The moose likes Applets and the fly likes Problems with applet running in IE brwser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Problems with applet running in IE brwser" Watch "Problems with applet running in IE brwser" New topic
Author

Problems with applet running in IE brwser

Paul Wagner
Greenhorn

Joined: Nov 13, 2009
Posts: 14
Hi Guys

I have written an applet, the code is the following

import java.awt.Graphics;
import java.applet.*;
public class HelloWorld extends Applet{
public void paint(Graphics g){

g.drawString("Hello World", 15, 30);
}
}

This runs fine in Eclipse.. But when I want to embedd this applet in html. Following is the html code

<html>
<body>
<applet code=HelloWorld height=100 width=100/>
</body>
</html>


The IE browser just shows an error message

java.lang.NoClassDefFoundError: HelloWorld (wrong name: helloWorldApplet/HelloWorld)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
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)

WHERE IS THE PROBLEM ? ClassPath is set, Path is set. In Eclipse its running, but not in IE.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Programmer newbee , please check your private messages.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41880
    
  63
Does your code have a "package helloWorldApplet" statement that you didn't post? If so, then the applet tag should read like "code=helloWorldApplet.HelloWorld".


Ping & DNS - my free Android networking tools app
Paul Wagner
Greenhorn

Joined: Nov 13, 2009
Posts: 14
thnx dittmer,

but when I add that, i get these exceptions


Laden: Klasse helloWorldApplet.HelloWorld nicht gefunden
java.lang.ClassNotFoundException: helloWorldApplet.HelloWorld
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:\Users\....\helloWorldApplet\HelloWorld.class (Das System kann den angegebenen Pfad nicht finden)
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
Ausnahme: java.lang.ClassNotFoundException: helloWorldApplet.HelloWorld
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41880
    
  63
Do you have the HelloWorld.class file inside of a folder called "helloWorldApplet" which itself is in the same folder as the HTML file? That's how the files must be organized.
Paul Wagner
Greenhorn

Joined: Nov 13, 2009
Posts: 14
oops you are right... I had put class file and html file in the same folder... it should be other way... class file in its own folder and html file and class folder should be in the same folder...
.
some time small things take more time to solve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problems with applet running in IE brwser