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

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:

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

posted Apr 24, 2004 04:54:00

0

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

posted Apr 24, 2004 05:36:00

0

Whoops, sorry. That was the wrong class file. :-p It worked fine with appletviewer, I just got an Exception Error: No suitable Driver.