Error: java.lang.NoClassDefFoundError: Chase (invalid name: pong / Chase)

I created an applet program using the Eclipse IDE. Now I am creating the .html file as shown below:

<html> <APPLET CODE="Chase.class" width=500 height=400> </APPLET> </html> 

When Im executing this file, im get error:

 java.lang.NoClassDefFoundError: Chase (wrong name: pong/Chase) 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) 

A new project is created in the Eclipse IDE and the program is packaged in the "pong" folder.

Can someone explain why this error occurs?

Edit:

Adding a few lines of Chase.java code to clarify. This is a simple applet:

 package pong; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class Chase extends Applet implements Runnable { ... } 
+6
java
source share
3 answers

There is no Chase class name in your classpath.

wrong name indicates that there may be an error with the class name with the specified package.

if the class declares package for example

 package a; public class MyApplet extends Applet{} 

then in HTML give a.MyApplet

Update

in your case it seems

<APPLET CODE="pong.Chase.class" width=500 height=400>

also the dir structure should be

 - - - - - | |-your html file |-pong folder | |- Chases.class 

will do if the package name is pong

+8
source share

I think the problem is basically the same as @Jigar Joshi noted, but with a slight wrinkle to it. I think you have a class whose FQN is "pong.Chase", but you created a class path so that the directory containing "Chase.class" is in the class path. Then you told the applet loader to look for the class as "Chase.class".

The class loader found the bytecode file, but then, when he tried to download it, he noticed that the FQN classes are "pong.Chase" and not "Chase" ... as the name that you gave. Ergo ... a NoClassDefFoundError with the message that the class name is incorrect.

The fix is ​​to make sure that the parent directory of the "pong" directory is in the class path and uses:

 <APPLET CODE="pong.Chase.class" width=500 height=400></APPLET> 

Alternatively, use the codeBase attribute.

Alternatively 2, get rid of the package declaration in your Java class.

Alternative 3 - use the <object> element. The <applet> element is deprecated.

Link: http://www.w3.org/TR/html401/struct/objects.html

+2
source share

You forgot part of the package in your applet tag:

 <APPLET CODE="pong.Chase.class" width=500 height=400> </APPLET> 
0
source share

All Articles