Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2002, 12:03 PM
vincent9999 vincent9999 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 8 vincent9999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Xerces example: NoClassDefFoundError

I was working on one of the Xerces tutorials on this site. I tested one of the code pieces on an xml file, and got the following error:
java.lang.NoClassDefFoundError org/xml/sax/SAXNotSupportedException.
It compiled no problem, but apparently this error means that "The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found." I have installed all the xerces files and have set the classpath to my bin with all those files in it. How can it find the class def to compile, but not find it to run? And why is it giving me a sax error when I am using the dom? Very strange...Has anybody who tried the Xerces tutorials encountered this problem? Thanks in advance for your help.


import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import java.io.*;

public class MyThirdDomApp {

// a counter for keeping track of the "tabs"
private int TabCounter = 0;

// constructor
public MyThirdDomApp (String xmlFile) {

// create a Xerces DOM parser
DOMParser parser = new DOMParser();

// parse the document and
// access the root node with its children
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
NodeDetails(document);
} catch (Exception e) {
System.err.println (e);
}
}

// this is a recursive function to traverse the document tree
private void NodeDetails (Node node) {
String Content = "";
int type = node.getNodeType();

// check if element
if (type == Node.ELEMENT_NODE) {
FormatTree(TabCounter);
System.out.println ("Element: " + node.getNodeName() );

// check if the element has any attributes
if(node.hasAttributes()) {

// if it does, store it in a NamedNodeMap object
NamedNodeMap AttributesList = node.getAttributes();
// iterate through the NamedNodeMap and get the attribute names and values
for(int j = 0; j < AttributesList.getLength(); j++) {
FormatTree(TabCounter);
System.out.println("Attribute: " +
AttributesList.item(j).getNodeName() + " = " +
AttributesList.item(j).getNodeValue());
}
}
} else if (type == Node.TEXT_NODE) {

// check if text node and print value
Content = node.getNodeValue();

if (!Content.trim().equals("")){
FormatTree(TabCounter);
System.out.println ("Character data: " + Content);
}
} else if (type == Node.COMMENT_NODE) {
// check if comment node and print value
Content = node.getNodeValue();
if (!Content.trim().equals("")){
FormatTree(TabCounter);
System.out.println ("Comment: " + Content);
}
}

// check if current node has any children
NodeList children = node.getChildNodes();
if (children != null) {
// if it does, iterate through the collection
for (int i=0; i< children.getLength(); i++) {
TabCounter++;
// recursively call function to proceed to next level
NodeDetails(children.item(i));
TabCounter--;
}
}
}

// this formats the output for the generated tree
private void FormatTree (int TabCounter) {
for(int j = 1; j < TabCounter; j++) {
System.out.print("\t");
}
}

// the main method to create an instance of our DOM application
public static void main (String[] args) {
MyThirdDomApp MyThirdDomApp = new MyThirdDomApp ("SomeFile.xml");
}
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Xerces example: NoClassDefFoundError


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway