• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jenova Child
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops, sorry. That was the wrong class file. :-p
It worked fine with appletviewer, I just got an Exception Error: No suitable Driver.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic