|
Subject:
|
Class Can't be instantiated
|
|
Posted By:
|
enderjs
|
Post Date:
|
9/29/2004 10:01:02 AM
|
Hello I have been working on this program, that parses an XML document and then displays the information in an applet. It keeps giving me the error:
java.lang.InstantiationException: DOMApplet at java.lang.Class.newInstance0(Class.java:293) at java.lang.Class.newInstance(Class.java:261) at sun.applet.AppletPanel.createApplet(AppletPanel.java:617) at sun.applet.AppletPanel.runLoader(AppletPanel.java:546) at sun.applet.AppletPanel.run(AppletPanel.java:298) at java.lang.Thread.run(Thread.java:534) load: DOMApplet.class can't be instantiated.
I looked it up and i think that it is because i have an abstract class. I have no idea how to fix it, if any one could help i would appreciate it. Here is the code that i have been working on. I have not finished the display part yet because i want to get it 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 format elements for display } protected void printText(CharacterData node) { //code to display XML } }
|
|