-
JDOM Errors Help Required
Hi Guys,
I am trying to follow an example using JDOM, which will write, update delete an XML file.
I thought I had set the JDOM & Xerces classpaths correctly, but I'm guessing not now:
I had one error in my java file as follows:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:81: illegal escape character
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\CATALOG1.xml"));
^
1 error
So I forgot the extra '\' in the path. Not a problem.
When I then went onto compile the java file thinking all was ok, I got the following errors:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:3: package org.jdom does not exist
import org.jdom.*;
^
CATALOGManager.java:4: package org.jdom.output does not exist
import org.jdom.output.XMLOutputter;
^
CATALOGManager.java:6: package org.jdom.input does not exist
import org.jdom.input.*;
^
CATALOGManager.java:7: package org.jdom.output does not exist
import org.jdom.output.*;
^
CATALOGManager.java:12: cannot find symbol
symbol : class Document
location: class XMLEdit.CATALOGManager
Document docs;
^
CATALOGManager.java:18: cannot find symbol
symbol : class SAXBuilder
location: class XMLEdit.CATALOGManager
SAXBuilder builder = new SAXBuilder();
^
CATALOGManager.java:18: cannot find symbol
symbol : class SAXBuilder
location: class XMLEdit.CATALOGManager
SAXBuilder builder = new SAXBuilder();
^
CATALOGManager.java:19: cannot find symbol
symbol : variable doc
location: class XMLEdit.CATALOGManager
doc = builder.build(filename);
^
CATALOGManager.java:20: cannot find symbol
symbol : variable doc
location: class XMLEdit.CATALOGManager
product = doc.getRootElement().getChildren();
^
CATALOGManager.java:21: cannot find symbol
symbol : class JDOMException
location: class XMLEdit.CATALOGManager
} catch (JDOMException e) {
^
CATALOGManager.java:36: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:36: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:41: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:41: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:47: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:47: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:53: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:53: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = (Element)product.get(index);
^
CATALOGManager.java:60: cannot find symbol
symbol : variable products
location: class XMLEdit.CATALOGManager
products.remove(index);
^
CATALOGManager.java:64: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = new Element("product");
^
CATALOGManager.java:64: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
Element product = new Element("product");
^
CATALOGManager.java:65: cannot find symbol
symbol : class Attribute
location: class XMLEdit.CATALOGManager
product.setAttribute(new Attribute("id", id));
^
CATALOGManager.java:66: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
product.addContent(new Element("name").setText(name));
^
CATALOGManager.java:67: cannot find symbol
symbol : class Element
location: class XMLEdit.CATALOGManager
product.addContent(new Element("price").setText(price));
^
CATALOGManager.java:73: cannot find symbol
symbol : class Sortname
location: class XMLEdit.CATALOGManager
catalog.sort(product, new Sortname());
^
CATALOGManager.java:73: cannot find symbol
symbol : variable catalog
location: class XMLEdit.CATALOGManager
catalog.sort(product, new Sortname());
^
CATALOGManager.java:78: cannot find symbol
symbol : variable XMLOutputter
location: class XMLEdit.CATALOGManager
XMLOutputter.output(" ",true);
^
CATALOGManager.java:80: cannot find symbol
symbol : variable outputter
location: class XMLEdit.CATALOGManager
outputter.setTextNormalize(true);
^
CATALOGManager.java:81: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:81: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:81: cannot find symbol
symbol : class File
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:82: cannot find symbol
symbol : variable doc
location: class XMLEdit.CATALOGManager
outputter.output(doc, f);
^
CATALOGManager.java:82: cannot find symbol
symbol : variable outputter
location: class XMLEdit.CATALOGManager
outputter.output(doc, f);
^
CATALOGManager.java:104: cannot find symbol
symbol : method setIndex(int)
location: class XMLEdit.CATALOGManager
d.setIndex(i);
^
CATALOGManager.java:111: cannot find symbol
symbol : class XMLOutputter
location: class XMLEdit.CATALOGManager
XMLOutputter outputter = new XMLOutputter();
^
CATALOGManager.java:111: cannot find symbol
symbol : class XMLOutputter
location: class XMLEdit.CATALOGManager
XMLOutputter outputter = new XMLOutputter();
^
CATALOGManager.java:113: cannot find symbol
symbol : variable doc
location: class XMLEdit.CATALOGManager
outputter.output(doc, System.out);
^
37 errors
Which I cant understand. Could someone helpout setting the classpath for JDOM. As I have put the JDOM & Xerces jar files in my classpath and set the path as follows (using the environment variable in Windows):
C:\Program Files\Java\jdk1.5.0_02\bin;.;C:\Program Files\Java\jdk1.5.0_02\lib\jdom.jar; C:\Program Files\Java\jdk1.5.0_02\lib\xerces.jar"C:\Tomcat 5.5\common\lib\servlet-api.jar";"C:\Tomcat 5.5\common\lib\jsp-api.jar";"C:\Tomcat 5.5\common\lib\catalina-root.jar";"C:\Tomcat 5.5\common\lib\jdom.jar";"C:\Tomcat 5.5\common\lib\xerces.jar"
Is this incorrect? Is this what the errors are referring to?
Any Help much appreciated.
Last edited by kpandya; 01-15-2006 at 07:12 PM.
-
The path is finicky.
Lose the quotation marks
Take out the space before the first "xerces" entry and add a semicolon after it before the next "C:\"
Put a semicolon at the end
-
Hi I amended the class path to as follows:
set CLASSPATH=.;"C:\Tomcat 5.5\common\lib\servlet-api.jar";"C:\Tomcat 5.5\common\lib\jsp-api.jar";"C:\Tomcat 5.5\common\lib\catalina-root.jar";"C:\Tomcat 5.5\common\lib\jdom.jar";"C:\Tomcat 5.5\common\lib\xerces.jar";"C:\Tomcat 5.5\webapps\ROOT\XMLEdit";C:\Program Files\Java\jdk1.5.0_02\lib\tools.jar;C:\Program Files\Java\jdk1.5.0_02\lib\jdom.jar;C:\Program Files\Java\jdk1.5.0_02\lib\xerces.jar;
Still get these errors:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:29: cannot find symbol
symbol : variable index
location: class XMLEdit.CATALOGManager
index = i;
^
CATALOGManager.java:38: cannot find symbol
symbol : variable index
location: class XMLEdit.CATALOGManager
Element product = (Element)products.get(index);
^
CATALOGManager.java:55: cannot find symbol
symbol : variable index
location: class XMLEdit.CATALOGManager
Element product = (Element)products.get(index);
^
CATALOGManager.java:57: cannot find symbol
symbol : method setValue(java.lang.String)
location: class org.jdom.Element
product.getChild("name").setValue(name);
^
CATALOGManager.java:58: cannot find symbol
symbol : method setValue(java.lang.String)
location: class org.jdom.Element
product.getChild("price").setValue(price);
^
CATALOGManager.java:62: cannot find symbol
symbol : variable index
location: class XMLEdit.CATALOGManager
products.remove(index);
^
CATALOGManager.java:70: cannot find symbol
symbol : method add(org.jdom.Element)
location: class org.jdom.Element
product.add(product);
^
CATALOGManager.java:75: cannot find symbol
symbol : class Sortname
location: class XMLEdit.CATALOGManager
catalog.sort(products, new Sortname());
^
CATALOGManager.java:75: cannot find symbol
symbol : variable catalog
location: class XMLEdit.CATALOGManager
catalog.sort(products, new Sortname());
^
CATALOGManager.java:80: cannot find symbol
symbol : method output(java.lang.String,boolean)
location: class org.jdom.output.XMLOutputter
XMLOutputter.output(" ",true);
^
CATALOGManager.java:82: cannot find symbol
symbol : variable outputter
location: class XMLEdit.CATALOGManager
outputter.setTextNormalize(true);
^
CATALOGManager.java:83: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:83: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:83: cannot find symbol
symbol : class File
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\X
MLEdit\\CATALOG1.xml"));
^
CATALOGManager.java:84: cannot find symbol
symbol : variable docs
location: class XMLEdit.CATALOGManager
outputter.output(docs, f);
^
CATALOGManager.java:84: cannot find symbol
symbol : variable outputter
location: class XMLEdit.CATALOGManager
outputter.output(docs, f);
^
CATALOGManager.java:106: cannot find symbol
symbol : method seti(int)
location: class XMLEdit.CATALOGManager
d.seti(i);
^
CATALOGManager.java:107: cannot find symbol
symbol : method getname()
location: class XMLEdit.CATALOGManager
System.out.println(d.getname() + "/" + d.getprice());
^
CATALOGManager.java:107: cannot find symbol
symbol : method getprice()
location: class XMLEdit.CATALOGManager
System.out.println(d.getname() + "/" + d.getprice());
^
CATALOGManager.java:115: cannot find symbol
symbol : variable docs
location: class XMLEdit.CATALOGManager
outputter.output(docs, System.out);
^
20 errors
I'm not sure if I have put the jdom.jar & xerces.jar in the right folders. Could anyone advise as to where I should be dropping the jar files.
-
you don't need "" s
I'd put them in the lib folder of your project. Also you have two paths to jdom.jar and xerces.jar
C:\Tomcat 5.5\common\lib\jdom.jar;C:\Tomcat 5.5\common\lib\xerces.jar;
C:\Program Files\Java\jdk1.5.0_02\lib\jdom.jar;C:\Program Files\Java\jdk1.5.0_02\lib\xerces.jar
I'm pretty sure the first one on the path will be used.
-
Do you not need the "" s if you have spaces in the paths?
for example Tomcat 5.5. This has a space in between so I though this has to be in quotes?
Ok I have tried every combination I can think of with the class path. I have placed the jdom.jar and xerces.jar files in the lib folder of my project, taken out the quotes. The classpath now looks like this:
set CLASSPATH=.;C:\Tomcat 5.5\common\lib\servlet-api.jar;C:\Tomcat 5.5\common\lib\jsp-api.jar;C:\Tomcat 5.5\common\lib\catalina-root.jar;C:\Tomcat 5.5\webapps\ROOT\WEB-INF\lib\jdom.jar;C:\Tomcat 5.5\webapps\ROOT\WEB-INF\lib\xerces.jar;C:\Tomcat 5.5\webapps\ROOT\XMLEdit;C:\Program Files\Java\jdk1.5.0_02\lib\tools.jar;
I still get the same errors. Is there any way to test the jar files or any kind of test that can be performed?
Last edited by kpandya; 01-14-2006 at 05:43 PM.
-
JDOM Errors
Hi Guys, I believe the problem I have is not now the classpath but something to do with the code:
I am still getting these errors:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:77: cannot find symbol
symbol : class SortName
location: class XMLEdit.CATALOGManager
Collections.sort(products, new SortName());
^
CATALOGManager.java:82: cannot find symbol
symbol : constructor XMLOutputter(java.lang.String,boolean)
location: class org.jdom.output.XMLOutputter
XMLOutputter outputter = new XMLOutputter(" ",true);
^
CATALOGManager.java:84: cannot find symbol
symbol : method setTextNormalize(boolean)
location: class org.jdom.output.XMLOutputter
outputter.setTextNormalize(true);
^
CATALOGManager.java:85: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\
MLEdit\\CATALOG.xml"));
^
CATALOGManager.java:85: cannot find symbol
symbol : class FileWriter
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\
MLEdit\\CATALOG.xml"));
^
CATALOGManager.java:85: cannot find symbol
symbol : class File
location: class XMLEdit.CATALOGManager
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\
MLEdit\\CATALOG.xml"));
^
Note: CATALOGManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
Now the errors only seem to stem when I insert these parts of code:
public void buildDocument(String filename) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("C:\\Tomcat 5.5\\webapps\\ROOT\\XMLEdit\\CATALOG.xml");
products = doc.getRootElement().getChildren();
} catch (JDOMException e) {
e.printStackTrace();
}
}
and
public void sort() {
Collections.sort(products, new SortName());
}
public void save(String filename) {
XMLOutputter outputter = new XMLOutputter(" ",true);
try {
outputter.setTextNormalize(true);
FileWriter f = new FileWriter(new File("C:\\Tomcat 5.5\\webapps\\ROOT\\XMLEdit\\CATALOG.xml"));
outputter.output(doc, f);
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Can any one see anything obvious that I am missing?
Many Thanks
Last edited by kpandya; 01-15-2006 at 07:14 PM.
Similar Threads
-
By Adam Dawes in forum VB Classic
Replies: 1
Last Post: 09-07-2001, 03:03 PM
-
By Adam Dawes in forum VB Classic
Replies: 1
Last Post: 09-07-2001, 03:03 PM
-
By David Rancour in forum Java
Replies: 1
Last Post: 08-01-2001, 10:58 AM
-
Replies: 1
Last Post: 09-29-2000, 09:33 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks