Hello to all.

I have build a Java GUI application and now i want to convert and transfer it to an applet.

I assume that whatever i have in

public void main

will now go to the init() method of the JApplet.

Now the problem is to embed it to the webpage...

I have this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="_css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<applet code="Applet1.class" width="400" height="300">
    
</<applet>
</body>
</html>

the index.html and Applet1.class are in the same directory but when i am trying to run the applet is loading and then its says

Error. Click here for details

I got this error report

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

I suppose the problem is here?

Applet1 (wrong name: sourceCode/Applet1)

where sourceCode is the package that i have declared in Eclipse???

When i run the Applet in Eclipse everything is ok, when i try to run it in browers i have the problem.

What i have to do?

Thanks in advance!

Recommended Answers

All 3 Replies

Hello to all.

I have build a Java GUI application and now i want to convert and transfer it to an applet.

I assume that whatever i have in

public void main

will now go to the init() method of the JApplet.

Not necessarily. It would probably be a good idea to put some of it into init and some of it into start, and possibly, some of it into stop, as well as defining additional "behaviour" for the start and stop methods.

Now the problem is to embed it to the webpage...

I have this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="_css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<applet code="Applet1.class" width="400" height="300">
    
</<applet>
</body>
</html>

the index.html and Applet1.class are in the same directory but when i am trying to run the applet is loading and then its says


I got this error report

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

I suppose the problem is here?

Applet1 (wrong name: sourceCode/Applet1)

where sourceCode is the package that i have declared in Eclipse???

When i run the Applet in Eclipse everything is ok, when i try to run it in browers i have the problem.

What i have to do?

Thanks in advance!

Looks like you refer to "sourceCode/Applet1" in your HTML. That would be correct if Applet1 was a part of the "sourceCode" package and was located in a directory "sourceCode" below the location of the HTML file. In any case, it should have a package and that package (the full package) should appear in directory under the location of the HTML (or use the CODEBASE attribute and a jarfile, or properly use JNLP).

I tried both ways and i have the same problem

First setup

folder test

  • index.html
  • Applet1.class

Html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="_css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<applet code="Applet1.class" width="400" height="300">
    
</<applet>
</body>
</html>

Second setup

test folder

  • index.html
  • sourceCode (folder)
    • Applet1.class

html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="_css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<applet code="Applet1.class" codebase="./sourceCode" width="400" height="300">
    
</<applet>



</body>
</html>

And i got the same error

Because you included the "codebase" parameter in the second. If you do that you are going to need another "sourceCode" directory under that "sourceCode" directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.