| Author |
Getting error Incompatible magic value 1784772193 in class file
|
sanyam Goel
Greenhorn
Joined: Jan 30, 2012
Posts: 8
|
|
Hello everyone,
I have created a custom loader. while reading class files form disk compiler throws an error "Exception in thread "AWT-EventQueue-0" java.lang.ClassFormatError: Incompatible magic value 1784772193 in class file.....
at java.lang.ClassLoader.defineClass1(Native Method)" It also includes the line of code containing the statement "classTemp= defineClass( classFilename, raw, 0, raw.length);" please suggest some solution
Thanks in advance
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 7602
|
|
Welcome to the Ranch.
This message usually indicates that you used a higher java version to compile the code, than the java version you are using to run it.
|
[Donate a pint, save a life!] [How to ask questions]
|
 |
Rob Spoor
Saloon Keeper
Joined: Oct 27, 2005
Posts: 18370
|
|
|
I don't think so. The error message for that is different: "unsupported class version". This one does mean that there's something wrong with the class files. Can you show us how you create a byte[] from the class file?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 7602
|
|
Oops!
Rob is right. As usual I am not thinking straight. Time for me to reboot.
|
 |
sanyam Goel
Greenhorn
Joined: Jan 30, 2012
Posts: 8
|
|
Rob Spoor wrote:I don't think so. The error message for that is different: "unsupported class version". This one does mean that there's something wrong with the class files. Can you show us how you create a byte[] from the class file?
This is the method I have created to convert a file to a byte array
Please Help!!
|
 |
sanyam Goel
Greenhorn
Joined: Jan 30, 2012
Posts: 8
|
|
Maneesh Godbole wrote:Welcome to the Ranch.
This message usually indicates that you used a higher java version to compile the code, than the java version you are using to run it.
Yes Maneesh I found this on Internet and I recompiled my classes to be loaded and and again re-ran the program.. but still I encountered the same problem
Here is the complete error I am getting again and again..
Exception in thread "AWT-EventQueue-0" java.lang.ClassFormatError: Incompatible magic value 1784772193 in class file DeckOfCards/class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at classLoader.ClassLoaderOfExtClass.loadClassCustom(ClassLoaderOfExtClass.java:161)
at guiTool.SeQuenceDiagramGeneration.jMenuItem1ActionPerformed(SeQuenceDiagramGeneration.java:136)
at guiTool.SeQuenceDiagramGeneration.access$0(SeQuenceDiagramGeneration.java:100)
at guiTool.SeQuenceDiagramGeneration$1.actionPerformed(SeQuenceDiagramGeneration.java:70)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Please Help!!
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 3221
|
|
You're using a String as an intermediary for binary data. That's just plain wrong. And in any case, the tostring() method of FileInputStream is inherited from Object -- what made you think that would return the content of the File?
You need to read the FIle into a byte array and use that to define the class. Also, is the 'classFilename' going to be the same as he expected binary name of the class? Think about it.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
sanyam Goel
Greenhorn
Joined: Jan 30, 2012
Posts: 8
|
|
Darryl Burke wrote:You're using a String as an intermediary for binary data. That's just plain wrong. And in any case, the tostring() method of FileInputStream is inherited from Object -- what made you think that would return the content of the File?
You need to read the FIle into a byte array and use that to define the class. Also, is the 'classFilename' going to be the same as he expected binary name of the class? Think about it.
Thank you so much Darryl !! Yes you were right now it is working perfectly fine 
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 3221
|
|
|
Now that you have it working, you may like to take a look at File Class Loader.
|
 |
Rob Spoor
Saloon Keeper
Joined: Oct 27, 2005
Posts: 18370
|
|
Darryl, I don't like your way of reading the file. There are two things that can go wrong:
1) fis.available() doesn't necessarily return the file size. Using (int)file.length() is safer. Only if the file is over 2TB large will that fail, but the entire file couldn't be put into a byte[] anyway.
2) fis.read(bytes) can often read less than the requested number of bytes. I'd instead use a DataInputStream around the FileInputStream and use its readFully method.
|
 |
 |
|
|
subject: Getting error Incompatible magic value 1784772193 in class file
|
|
|