Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 28th, 2004, 03:08 PM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
    }

}

 
Old September 29th, 2004, 02:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would be very surprised if an Applet could open a local file, perhaps that's why it is failing.

--

Joe (Co-author Beginning XML, 3rd edition)





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 J2EE 0 September 29th, 2004 10:01 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.