-
[B]Java Bean to control JSP pages[/B]
Hi,
I am very new to Java and need some help with some errors I get trying to run a java bean. The code is below which will be used to for a web application to manage a list of products held in an XML file. It uses JDOM. The bean contains a create, update and delete method and a method to build the document tree. Based on the example / tutorial "Java and JDOM: the perfect couple"
The errors I get are as follows:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:70: cannot find symbol
symbol : variable PRODUCT
location: class XMLEdit.CATALOGManager
PRODUCT.sort(PRODUCT, new sortname());
^
CATALOGManager.java:70: cannot find symbol
symbol : class sortname
location: class XMLEdit.CATALOGManager
PRODUCT.sort(PRODUCT, new sortname());
^
CATALOGManager.java:70: cannot find symbol
symbol : variable PRODUCT
location: class XMLEdit.CATALOGManager
PRODUCT.sort(PRODUCT, new sortname());
^
CATALOGManager.java:74: cannot find symbol
symbol : constructor XMLOutputter(java.lang.String,boolean)
location: class org.jdom.output.XMLOutputter
XMLOutputter outputter = new XMLOutputter(" ",true);
^
CATALOGManager.java:76: cannot find symbol
symbol : method setTextNormalize(boolean)
location: class org.jdom.output.XMLOutputter
outputter.setTextNormalize(true);
^
Note: CATALOGManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
package XMLEdit;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import java.util.*;
import java.io.*;
public class CATALOGManager {
Document doc; // JDOM document
List products; // List of Elements
int index = -1; // index for current Element in "catalogue"
public void buildDocument(String filename) {
try {
SAXBuilder builder = new SAXBuilder();
doc = builder.build(filename);
products = doc.getRootElement().getChildren();
} catch (JDOMException e) {
e.printStackTrace();
}
}
public void setIndex(int i) {
index = i;
}
public int getNumberOfProducts() {
return products.size();
}
public String getId() {
Element product = (Element)products.get(index);
return product.getAttributeValue("id");
}
public String getname() {
Element product = (Element)products.get(index);
return product.getChildText("name");
}
public String getprice() {
Element product = (Element)products.get(index);
return product.getChildText("price");
}
public void updatePRODUCT(String id, String name, String price) {
Element product = (Element)products.get(index);
product.getAttribute("id").setValue(id);
product.getChild("name").setText(name);
product.getChild("price").setText(price);
}
public void deletePRODUCT() {
products.remove(index);
}
public void createPRODUCT(String id, String name, String price) {
Element product = new Element("product");
product.setAttribute(new Attribute("id", id));
product.addContent(new Element("name").setText(name));
product.addContent(new Element("price").setText(price));
products.add(product);
}
public void sort() {
PRODUCT.sort(PRODUCT, new sortname());
}
public void save(String filename) {
XMLOutputter outputter = new XMLOutputter(" ",true);
try {
outputter.setTextNormalize(true);
FileWriter f = new FileWriter(new File(filename));
outputter.output(doc, f);
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CATALOGManager d = new CATALOGManager();
d.buildDocument(args[0]);
//d.updatePRODUCT("New NAME", "123");
//d.createPRODUCT("New NAME2", "1234");
//d.deletePRODUCT(0);
//d.deletePRODUCT(0);
//d.deletePRODUCT(0);
//d.createPRODUCT("New NAME", "123");
//d.updatePRODUCT(0, "Next NAME", "7913");
//d.deletePRODUCT(0);
//d.outList();
d.sort();
for (int i = 0; i < d.products.size(); i++) {
d.setIndex(i);
System.out.println(d.getname() + "/" + d.getprice());
}
}
private void outList() {
XMLOutputter outputter = new XMLOutputter();
try {
outputter.output(doc, System.out);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I cant see what I have done wrong any Help greatly appreciated..
-
It can't find the Classes and methods as stated in the errors. Are the classes and latest classes available to the compiler? Remember that Java is case sensitive.
-
Errm, I think so.
I think I understand the problem, I have declared CATALOGManager with the "variable" d so d.updatePRODUCT(..) should actually be d.updateCATALOGManager(..) is that right?
Apologies if "variable" was used in the wrong sense. I have only started to learning so get confused with all the terminology.
Am I on the right track with what I said above or heading in the wrong direction with that?
Well I have tried to run the java file again and get similar errors:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:70: cannot find symbol
symbol : variable product
location: class XMLEdit.CATALOGManager
CATALOGManager.sort(product, new sortname());
^
CATALOGManager.java:70: cannot find symbol
symbol : class sortname
location: class XMLEdit.CATALOGManager
CATALOGManager.sort(product, new sortname());
^
CATALOGManager.java:74: cannot find symbol
symbol : constructor XMLOutputter(java.lang.String,boolean)
location: class org.jdom.output.XMLOutputter
XMLOutputter outputter = new XMLOutputter(" ",true);
^
CATALOGManager.java:76: cannot find symbol
symbol : method setTextNormalize(boolean)
location: class org.jdom.output.XMLOutputter
outputter.setTextNormalize(true);
^
Note: CATALOGManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
I cant understand why these errors are occuring. What am I doing wrong?
Many Thanks
Last edited by kpandya; 01-11-2006 at 02:34 PM.
-
Ok can anyone shed any light on the error I am seeing now, I have managed to get down to one error:
Ok I have got it down to one error:
C:\Tomcat 5.5\webapps\ROOT\XMLEdit>javac CATALOGManager.java
CATALOGManager.java:18: unreported exception java.io.IOException; must be caught
or declared to be thrown
doc = builder.build(filename);
^
Note: CATALOGManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
What is this error referring to and why is it pointing it to this particular line of code?
Many Thanks
Similar Threads
-
By Prometheus in forum Java
Replies: 0
Last Post: 02-20-2005, 01:06 PM
-
By Glen Kunene in forum Talk to the Editors
Replies: 17
Last Post: 03-23-2002, 12:43 AM
-
Replies: 3
Last Post: 04-14-2001, 04:01 PM
-
By MacDeath in forum VB Classic
Replies: 2
Last Post: 02-14-2001, 05:44 AM
-
By Jerry Bumgarner in forum VB Classic
Replies: 4
Last Post: 07-14-2000, 10:48 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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|