Class can't be instantiated?
Hello, I am working on an applet that parses an XML document and displays the information. I cant figuere out this error.
"load: DOMApplet.class can't be instantiated"
I looked for the reason and I found that it may be because my class is abstract. I have no idea how to fix it. If any one could help, I would be grateful. Thanks
Here is the code that I have been working on, I havent completed the display part because i want to be able to parse the document first.
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.applet.Applet;
import java.awt.Graphics;
public class DOMApplet extends java.applet.Applet {
StringBuffer buffer;
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
}
public void start() {
try {
//tells the program to create an new parser and parse the document
DOMApplet da = new DOMApplet("C:\\Documents and Settings\\jason.silvers\\My Documents\\DOMTest3\\Newproductlist2.xml");
}
catch (Exception ex) {
System.out.println (ex.getMessage());
}
}
public DOMApplet(String uri) {
try {
//builds the factory to parse the file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
//the file is parsed and saved to memory
Document doc = builder.parse(uri);
//retrives the document and gets it ready to be displayed
displayTree(doc.getDocumentElement());
// System.out.println(doc.getDocumentElement());
}
catch (Exception ex) {
System.out.println (ex.getMessage());
}
}
public void displayTree(Node node) {
short nodeType = node.getNodeType();
switch (nodeType) {
case Node.ELEMENT_NODE:
printElement((Element)node);
break;
case Node.ATTRIBUTE_NODE:
printElement((Element)node);
break;
case Node.TEXT_NODE:
printText((Text)node);
default:
}
}
protected void printElement(Element node) {
// code to Determines the format to diplay the XML Data Element
}
protected void printText(CharacterData node) {
// Code to display the data.
}
}
|