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

NoClassDefFoundError

Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Anyone know how to remody this lovely error:

java.lang.NoClassDefFoundError: hang_cipher/Applet_Control (wrong name: Applet_Control)

This appears after I have passed through the security warning. Unverified signature.
The resource is a JApplet

Java defines this error as "Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. "

Does this mean that I have to supply all the java libraries I am using with the applet. This would seem a little excessive.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Welcome to JavaRanch.

The "wrong name" part usually indicates that there's something wrong with the package or directory hierarchy. Is class Applet_Control in package hang_cipher? And is it inside a directory of that name and that directory is at the same level as the HTML file containing the applet tag? Or, if you're using a jar file- is that correctly packaged?

Does this mean that I have to supply all the java libraries I am using with the applet. This would seem a little excessive.

I'm not sure what you mean by that. All 3rd party libraries used by the applet need to be available at runtime, and be specified in the applet tag.


Ping & DNS - my free Android networking tools app
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Thanks for the help.

The structure is as follows:

I am using a server www.computingscotland.org although I don't have root access to the server.

Check it out its a lovely site to encourage kids to study Computer Science.

In the folder '/' which is the top level area I have access too i.e. the area where all the files are stored is a page .php file in which the JApplet is embeded.(address http://www.computingscotland.org/hangcipher.php)

It has been embeded as follows:

<!--[if !IE]>-->
<object classid="java:hang_cipher.Applet_Control.class"
type="application/x-java-applet"
archive="/Applet/hang_cipher.jar"
height="800" width="710" >
<!-- Konqueror browser needs the following param -->
<param name="archive" value="/Applet/hang_cipher.jar"/>
<!--<![endif]-->

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
height="800" width="710" >
<param name="code" value="hang_cipher.Applet_Control" />
<param name="archive" value="/Applet/hang_cipher.jar"/>
</object>
<!--[if !IE]>-->
</object>
<!--<![endif]-->

The jar file containing the code is here

http://www.computingscotland.org/Applet/hang_cipher.jar

Inside the jar file is a package called hang_cipher and inside this package is Applet_Control which extends JApplet

I have not used any 3rd party packages but have made use of swing, io ect. which java has provided.

Hope I can get this working.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
The problem is that class Applet_Control is not actually in package hang_cipher; it is not in any package, and thus should not be in a directory inside of the jar file, and should not be referenced as if it were.
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
I have package statements at the top of each of my java files, in eclipse it is within a package and this looks like a folder when using windows explorer. So I'm a bit confused.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
That's odd, because the source files (which were included in the jar file) do not have a package statement.
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Well Spotted, thanks for the help as well.

I thought I had uploaded a different version, I guess not
Ok I removed the hang_cipher. part but it returns the same error message
you can will be verify this from page source and the jar file

Quite a frustrating problem and Im not sure how to proceed.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
I just downloaded the jar file again - the source still doesn't have package statements.
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Yes I know I thought I would try it without the package statements, I have removed the references to a package to reflect this.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Originally posted by Simon Poet:
Yes I know I thought I would try it without the package statements, I have removed the references to a package to reflect this.


But all the classes are still inside of the hang_cipher directory in the jar file; that's why it doesn't work.
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Ok I tried this I successfully created a jar files where the classes were not in a directory but jarsigner puts them in a directory.
I am using the command

jarsigner hang_cipher.jar myalias
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Ok I have got passed this error. The heirarchy of the jar file was wrong. I managed to get passed the error by holding all my files in a package which was in the jar file. One directory depth seems to be both the minimum and the maximum for a signed jar file.

But now I have a null pointer exception but that's programming for you

I would conclude that if you sign a jar then it must be in a package because it puts all the files into a directory.
Simon Poet
Greenhorn

Joined: Sep 06, 2007
Posts: 8
Oh one more point, I was using the eclipse IDE but whenever I build my .jar using java jar tool it would mess up the hierarchy perhaps its got something to do with how eclipse lays out its files. Better to use the Export function in eclipse to generate the .jar

[ September 07, 2007: Message edited by: Simon Poet ]
[ September 07, 2007: Message edited by: Simon Poet ]
Amit Saste
Greenhorn

Joined: Sep 06, 2007
Posts: 6
hi,file name and class name of the program should be same.also check whether the class file you are passing to HTML code is f the respective public class.
if not solved,please patch small code thats why we could come to understand exact problem.
 
 
subject: NoClassDefFoundError