Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2004, 10:01 AM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class Can't be instantiated

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.ja va: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
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Why abstract class can't be instantiated? anisurr C++ Programming 5 July 23rd, 2008 01:32 AM
WinForm Resizing instantiated form inside Tab Page maulik33 C# 4 June 13th, 2007 01:48 PM
from where is Instance actually instantiated? rocco50 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 March 1st, 2007 03:52 PM
Class can't be instantiated? enderjs XML 1 September 29th, 2004 02:05 AM
COM out of process server (EXE) instantiated twice sebdejonghe C++ Programming 0 March 31st, 2004 09:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.