Could anybody tell me why I'm getting this error, and how to fix the problem?
有没有人能告诉我为什么我犯了这个错误,怎么解决这个问题?
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/stax2/ri/Stax2ReaderAdapter at org.codehaus.staxmate.dom.DOMConverter._build(DOMConverter.java:188) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:171) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:152) at org.codehaus.staxmate.dom.DOMConverter.buildDocument(DOMConverter.java:131) at xmlprocessing.api.STAXModifyCV.main(STAXModifyCV.java:68) Caused by: java.lang.ClassNotFoundException: org.codehaus.stax2.ri.Stax2ReaderAdapter at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 5 more Java Result: 1
线程“main”java.lang中的异常。NoClassDefFoundError: org.codehaus.staxmate. domconverter._build (DOMConverter.java:188)在org. codehaus.staxmate.org . builddocument (DOMConverter.java:171)在org. codehaus.staxmate.org . builddocument (domconverter.java:152)在xmlprocess . staxmodifycv .main(STAXModifyCV.java:68)中所引起的:java.lang。ClassNotFoundException:org.codehaus.stax2.ri。at java.net.URLClassLoader$1.run(URLClassLoader.java:202)在java.security.AccessController。在java.net.URLClassLoader.findClass(URLClassLoader.java:190)在java.lang.ClassLoader.loadClass(ClassLoader.java:307)上,在java.lang.ClassLoader.loadClass(ClassLoader.java:248)中,加载类(Launcher.java:301)。5更多Java结果:1。
I wrote the code below:
我写了下面的代码:
//-*-*-
FileInputStream input = new FileInputStream("cv.xml");
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//-*-*- get new entries from input stream
System.out.println("<< Sahar CV >>\n -> Modify the first reference\n ** Modify The Name **");
System.out.print(" Enter degree : ");
String degree = in.readLine();
System.out.print(" Enter first name : ");
String fName = in.readLine();
System.out.print(" Enter last name : ");
String lName = in.readLine();
System.out.println(" ** Modify The Address ** ");
System.out.print(" Enter new city : ");
String newCity = in.readLine();
System.out.print(" Enter new country : ");
String newCountry = in.readLine();
//-*-*- let the reader point at the first "reference" element
int eventType;
boolean ref = false, fname = false;
while (!ref && reader.hasNext()) {
eventType = reader.next();
switch (eventType) {
case XMLEvent.START_ELEMENT:
if (reader.getLocalName().equalsIgnoreCase("references")) {
ref = true;
break;
}
}
}
System.out.println("I am here");
//-*-*- start modification
Document doc = new DOMConverter().buildDocument(reader);
Element firstRef = (Element)doc.getElementsByTagName("reference").item(0);
NodeList name = (NodeList)firstRef.getElementsByTagName("name");
//-*-*- modify the degree (Dr. , Eng. , Dev. ,etc)
Attr att = (Attr)name.item(0).getAttributes().item(0);
((Node)att).setNodeValue(degree);
//-*-*- modify first name
NodeList firstName = (NodeList)firstRef.getElementsByTagName("fname");
NodeList firstNameChilds = (NodeList)firstName.item(0).getChildNodes();
((Node)firstNameChilds.item(0)).setNodeValue(fName);
//-*-*- modify last name
NodeList lastName = (NodeList)firstRef.getElementsByTagName("lname");
NodeList lastNameChilds = (NodeList)lastName.item(0).getChildNodes();
((Node)lastNameChilds.item(0)).setNodeValue(lName);
//-*-*- modify city
NodeList city = (NodeList)firstRef.getElementsByTagName("city");
NodeList cityChilds = (NodeList)city.item(0).getChildNodes();
((Node)cityChilds.item(0)).setNodeValue(newCity);
//-*-*- modify country
NodeList country = (NodeList)firstRef.getElementsByTagName("country");
NodeList countryChilds = (NodeList)country.item(0).getChildNodes();
((Node)countryChilds.item(0)).setNodeValue(newCountry);
reader.close();
input.close();
//-*-*- write DOM document
FileOutputStream out = new FileOutputStream("cv.xml");
XMLStreamWriter sw = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
new DOMConverter().writeDocument(doc, sw);
sw.close();
out.close();
3 个解决方案
#1
0
Sorry I voted down on the 3 answers but suddenly had a doubt and needed to double check what I thought ... and it ended up being more complex than I thought. However I found a very complete answer for you here: http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR
对不起,我否决了3个答案,但突然间我有了疑问,需要仔细检查我的想法……结果比我想象的要复杂得多。不过,我在这里找到了一个非常完整的答案:http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR。
#2
5
You need to make sure the right Woodstox is in your path. Basically, you're using a class that's implemented in that jar, but because the jar isn't in the path Java has no idea what class you're referencing.
您需要确保正确的Woodstox在您的路径中。基本上,您使用的是在那个jar中实现的类,但是因为jar不在路径中,Java不知道您在引用哪个类。
#3
3
This means that a .class file was found that didn't contain the expected class, either because the package doesn't correspond with the directory structure or because the file was renamed after compilation. There are other causes but this is the most common.
这意味着一个.class文件被发现没有包含预期的类,要么是因为这个包不符合目录结构,要么是因为文件在编译后重命名了。还有其他原因,但这是最常见的。
#1
0
Sorry I voted down on the 3 answers but suddenly had a doubt and needed to double check what I thought ... and it ended up being more complex than I thought. However I found a very complete answer for you here: http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR
对不起,我否决了3个答案,但突然间我有了疑问,需要仔细检查我的想法……结果比我想象的要复杂得多。不过,我在这里找到了一个非常完整的答案:http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR。
#2
5
You need to make sure the right Woodstox is in your path. Basically, you're using a class that's implemented in that jar, but because the jar isn't in the path Java has no idea what class you're referencing.
您需要确保正确的Woodstox在您的路径中。基本上,您使用的是在那个jar中实现的类,但是因为jar不在路径中,Java不知道您在引用哪个类。
#3
3
This means that a .class file was found that didn't contain the expected class, either because the package doesn't correspond with the directory structure or because the file was renamed after compilation. There are other causes but this is the most common.
这意味着一个.class文件被发现没有包含预期的类,要么是因为这个包不符合目录结构,要么是因为文件在编译后重命名了。还有其他原因,但这是最常见的。