Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Missing Class?

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Missing Class?

    I'm getting the follow exception when I run my applet in the browser (not the IDE):

    Exception in thread "Thread-17" java.lang.ClassFormatError: Incompatible magic value 1013478509 in class file <html><head>
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at javax.xml.parsers.FactoryFinder.getProviderClass(U nknown Source)
    at javax.xml.parsers.FactoryFinder.newInstance(Unknow n Source)
    at javax.xml.parsers.FactoryFinder.findJarServiceProv ider(Unknown Source)
    at javax.xml.parsers.FactoryFinder.find(Unknown Source)
    at javax.xml.parsers.DocumentBuilderFactory.newInstan ce(Unknown Source)
    at com.apmsoftware.utilities.xml.XMLUtilities.loadXML FromURL(XMLUtilities.java:196)
    at com.apmsoftware.airlinegame.shared.services.Config urationsQuery.readConfigurationsFile(Configuration sQuery.java:42)
    at com.apmsoftware.airlinegame.application.shared.ser vices.LoadDataService.loadStartupData(LoadDataServ ice.java:35)
    at com.apmsoftware.airlinegame.application.web.gui.Ai rlineGameApplet$1.run(AirlineGameApplet.java:33)
    at java.lang.Thread.run(Unknown Source)
    It seems to be the start of an HTML page, which would suggest an error indicating a missing class (to my understanding).
    I believe the offending code is my XMLUtilities.loadXMLFromURL(...) method. Here is the code for that method (with imports):
    import java.net.URL;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
     
    public static Document loadXMLFromURL(URL xml) throws Exception {
    		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     
    	    factory.setNamespaceAware(true);
    	    DocumentBuilder builder = factory.newDocumentBuilder();
     
    	    return builder.parse(xml.openStream());
    	}

    Is there any noticeable problems in that method? As far as I know, all of those classes are in the normal java api.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Missing Class?

    Can you post an SSCCE instead of a snippet?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Missing Class?

    Well I think I found out the cause (very odd). I will update with a solution once I find one, in case someone else comes across this issue.

    Cause:
    It turns out that java does not find DocumentBuilderFactory when deployed in a browser. For whatever reason, it doesn't check the JRE first for that particular class. First it checks the applet's dependencies. If it can't find the class, it then it checks the applet's host server. If it still can't find it, it checks the JRE. This is where the problem is. If the class is not found on the host server, the server will reply with its default 404 page. Depending on how your 404 page is set up, Java may not recognize it as a 404 page and simply throw a parsing error (stating that it found an html tag and it doesn't know what to do with it) instead of moving to the JRE.

    --- Update ---

    Just wanted to add the Javadoc which proves my cause argument:
    DocumentBuilderFactory (Java Platform SE 6)

    --- Update ---

    Solution:
    A system property needs to be set for the DocumentBuildFactory. I changed my loadXMLFromURL() method to this:
    import java.net.URL;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
     
    public static Document loadXMLFromURL(URL xml) throws Exception {
    	//I just had to add this line	
    	System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
     
    	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     
    	factory.setNamespaceAware(true);
    	DocumentBuilder builder = factory.newDocumentBuilder();
     
    	return builder.parse(xml.openStream());
    }
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Missing class file
    By Skybear in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 7th, 2013, 08:07 PM
  2. [SOLVED] 'ELSE' missing 'IF'
    By Andrew Red in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 30th, 2013, 11:51 AM
  3. Replies: 3
    Last Post: December 2nd, 2012, 11:18 PM
  4. What am I missing?
    By jean28 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2012, 10:49 AM
  5. What am I missing?
    By prgmrGrl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 10th, 2012, 12:33 AM