NoSuchMethodError: main


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: NoSuchMethodError: main

  1. #1
    Join Date
    Sep 2004
    Posts
    4

    NoSuchMethodError: main

    Hello, I am having a problem getting this program to run. I keep getting the error;

    java.lang.NoSuchMethodError: main
    Exception in thread "main"

    and i cant find the problem.I am having trouble also becuause i dont have a main in my program because it is an applet. If any one can shed some light on me that would be great. Here is the code that i have been working on.

    The object of the code is to import an XML document and display the nodes in an applet. If you want some additional information do not hesitate to ask.

    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    import java.applet.Applet;
    import java.awt.Graphics;


    public class DOMTest3 extends Applet {

    StringBuffer buffer;

    public void init() {


    }
    public void start() {

    try {
    //tells the program to create an new parser and parse the document
    DOMTest3 dt = new DOMTest3("C:\\Documents and Settings\\jason.silvers\\My Documents\\DOMTest3\\Newproductlist2.xml");
    }
    catch (Exception ex) {
    System.out.println (ex.getMessage());
    }



    }
    public DOMTest3(String uri) {
    //builds the factory to parse the file

    try {
    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());
    }

    }


    //formattes the XML to be displayed.
    protected 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) {
    Node child;
    Attr attr;

    addItem("<" + node.getNodeName() + ">" );
    NamedNodeMap attrs = node.getAttributes();
    int count = attrs.getLength();
    for (int i = 0; i < count; i++) {
    attr = (Attr)(attrs.item(i));
    addItem("<" + attr.getName() + "=\"" + attr.getValue() + "\"" );
    //System.out.println();

    }
    //System.out.print(">");
    NodeList children = node.getChildNodes();
    // int count = children.getLength();
    for (int i = 0; i < count; i++) {
    child = children.item(i);
    displayTree(child);
    }
    addItem("<" + node.getNodeName() + ">" );
    //System.out.println();

    }

    protected void printText(CharacterData node) {
    addItem(node.getData());
    }
    void addItem(String newWord) {
    System.out.println(newWord);
    buffer.append(newWord);
    //repaint();
    }

    }


  2. #2
    Join Date
    May 2004
    Posts
    219
    It's an applet... so use appletviewer. You are trying to run it as an application, which is wrong.

  3. #3
    Join Date
    Sep 2004
    Posts
    4

    Instantiation Error

    I put it into an appletviewer and when i did it gave me this error, i have tried everything to fix it and i cant think of anything else. Please Help.

    java.lang.InstantiationException: DOMTest3
    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: DOMTest3.class can't be instantiated.

    I think that it is because i have an abstract class, but i dont understand how.

  4. #4
    Join Date
    Sep 2004
    Posts
    7

    applet

    I think the problem is from your init() ...have a look at it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center