File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number)" Watch "java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number)" New topic
Author

java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number)

Jenova Child
Greenhorn

Joined: Apr 23, 2004
Posts: 3
Hey.
I am trying to connect to a MySQL database using java, I have successfully installed the jdbc driver. I know this for a fact because when I create an actual java 'application' and run a query, It works fine and I get the desired result. But when I try and connect to the database from an applet, I get the following error:
java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Chatroom.init(Chatroom.java:24)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I am running WinXP and Apache, with j2sdk1.4.2_04. I'm not sure if the error is in my code, or the way I have the server running. I am very new to java, here is my source code below:



Thanks, any help would be appreciated.
- Jenova Child
[ April 23, 2004: Message edited by: Jenova Child ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Jenova,
Welcome to JavaRanch. The magic number of a file is the first 4 bytes of the file which is CAFEBABE (in hex) for a Java class file. It comes from Unix systems which used the magic number to determine the file type by inspecting the magic number for binary files instead of assuming the file type by the file extension. ClassLoaders insist that the magic number and that the versions match for the VM in use. The gist of all this is that it would appear that you have a corrupt class file or a different Java plugin version which the applet is using. Try using appletviewer instead of a browser and see if it works, if so you need to first verify that the version of Java that you are developing on matches the plugin version and that you don't have more than one copy of the driver class (one being corrupt) and different CLASSPATHs for the application and applet.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Jenova Child
Greenhorn

Joined: Apr 23, 2004
Posts: 3
Thanks.
I already looked up the HEX code for the class files and they both begin with CAFE BABE. I tried runnning the applet through appletviewer and this is what i got:
java.lang.NoClassDefFoundError: Chatroom2$1
at Chatroom2.start(Chatroom2.java:33)
at sun.applet.AppletPanel.run(AppletPanel.java:377)
at java.lang.Thread.run(Thread.java:534)
Jenova Child
Greenhorn

Joined: Apr 23, 2004
Posts: 3
Whoops, sorry. That was the wrong class file. :-p
It worked fine with appletviewer, I just got an Exception Error: No suitable Driver.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassFormatError: com/mysql/jdbc/Driver (Bad magic number)
 
Similar Threads
Issues with cmd java command
Problem running Spring in a java applet
WAMP/Java/MysqlConnector Issue
weblogic 10.3 + jdk6.0.14 = java applet problem?
Applet in JSP