Error: Could not find or load main class while parsing an XML file

user2991413

I am trying to parse an XML file into java class. But it is giving me an Error saying

Could not find or load main class

The XML file which i am parsing is in same directory as the PretechDOMReader.java file

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class PretechDOMReader {
       public static void main(String[] args) {
              try {
                     File fXmlFile = new File("PretechDOM.xml");
                     DocumentBuilderFactory dbFactory = DocumentBuilderFactory
                                  .newInstance();
                     DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                     Document doc = dBuilder.parse(fXmlFile);
                     doc.getDocumentElement().normalize();
                     System.out.println("Order Details"
                                  + doc.getDocumentElement().getNodeName());
                     NodeList nList = doc.getElementsByTagName("Ordernumber");

                     for (int temp = 0; temp < nList.getLength(); temp++) { 
                           Node nNode = nList.item(temp);

                           if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                                  Element eElement = (Element) nNode;
                                  Node orderedItem1 = (Node) (NodeList) eElement
                                                .getElementsByTagName("OrderedItem1").item(0)
                                                .getChildNodes().item(0);
                                  System.out.println("OrderedItem1   :"
                                                + orderedItem1.getNodeValue());

                                  Node orderitemPrice = (Node) (NodeList) eElement
                                                .getElementsByTagName("OrderitemPrice").item(0)
                                                .getChildNodes().item(0);
                                  System.out.println("OrderitemPrice   :"
                                                + orderitemPrice.getNodeValue());
                                  Node orderitemTax = (Node) (NodeList) eElement
                                                .getElementsByTagName("OrderitemTax").item(0)
                                                .getChildNodes().item(0);
                                  System.out.println("OrderitemTax   :"
                                                + orderitemTax.getNodeValue());
                                  Node orderDiscount = (Node) (NodeList) eElement
                                                .getElementsByTagName("OrderDiscount").item(0)
                                                .getChildNodes().item(0);
                                  System.out.println("OrderDiscount   :"
                                                + orderDiscount.getNodeValue());
                           }
                     }
              } catch (Exception e) {
                     e.printStackTrace();
              }
       }

}

Here is my XML file

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Order>
    <Ordernumber Number="9988">
        <OrderedItem1>Pepsi</OrderedItem1>
        <OrderitemPrice>10</OrderitemPrice>
        <OrderitemTax>10</OrderitemTax>
        <OrderDiscount>20</OrderDiscount>
    </Ordernumber>
    <Ordernumber Number="9999">
        <OrderedItem1>Cocacola</OrderedItem1>
        <OrderitemPrice>11</OrderitemPrice>
        <OrderitemTax>11</OrderitemTax>
        <OrderDiscount>22</OrderDiscount>
    </Ordernumber>

Ninad Pingale

Your code is working well. Please check Class Path setting of your project in Eclipse.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Error: Could not find or load main class - .jar file execution

From Java

Heroku "could not find or load main class" error

From Java

Error: Could not find or load main class CountRows?

From Java

Error: Could not find or load main class

From Java

.jar error - could not find or load main class

From Java

Error: Could not find or load main class version

From Java

Eclipse "Error: Could not find or load main class"

From Java

Error: Could not find or load main class cucumber.cli.Main

From Java

Error: Could not find or load main class HelloWorld

From Dev

Executing batch file error: "Could not find or load main class"

From Dev

Flink Error: Could not find or load main class

From Dev

Error: Could not find or load main class while executing jar file

From Dev

Java - Error : Could not find or load main class

From Dev

Error: Could not find or load main class(Java)

From Dev

Error: Could not find or load main class Main

From Dev

Error: Could not find or load main class Main (unix)

From Dev

Error : Could not find or load main class Protection

From Dev

error: could not load or find main class xyz

From Dev

Error Could not find or load main class

From Dev

Error: Could not find or load main class?

From Dev

Error: Could not find or load main class

From Dev

Error: Could not find or load main class ClassDemo

From Dev

Error: Could not find or load main class Akash

From Dev

Error Could not find or load main class (java)

From Dev

Error: Could not find or load main class while class is included in the jar file

From Dev

Error: could not find or load main class in java

From Dev

Error: Could not find or load main class MyCSVParser

From Dev

Getting Error: Could not find or load main class while opening executable Jar file

From Dev

IntelliJ: Error: Could not find or load main class

Related Related

  1. 1

    Error: Could not find or load main class - .jar file execution

  2. 2

    Heroku "could not find or load main class" error

  3. 3

    Error: Could not find or load main class CountRows?

  4. 4

    Error: Could not find or load main class

  5. 5

    .jar error - could not find or load main class

  6. 6

    Error: Could not find or load main class version

  7. 7

    Eclipse "Error: Could not find or load main class"

  8. 8

    Error: Could not find or load main class cucumber.cli.Main

  9. 9

    Error: Could not find or load main class HelloWorld

  10. 10

    Executing batch file error: "Could not find or load main class"

  11. 11

    Flink Error: Could not find or load main class

  12. 12

    Error: Could not find or load main class while executing jar file

  13. 13

    Java - Error : Could not find or load main class

  14. 14

    Error: Could not find or load main class(Java)

  15. 15

    Error: Could not find or load main class Main

  16. 16

    Error: Could not find or load main class Main (unix)

  17. 17

    Error : Could not find or load main class Protection

  18. 18

    error: could not load or find main class xyz

  19. 19

    Error Could not find or load main class

  20. 20

    Error: Could not find or load main class?

  21. 21

    Error: Could not find or load main class

  22. 22

    Error: Could not find or load main class ClassDemo

  23. 23

    Error: Could not find or load main class Akash

  24. 24

    Error Could not find or load main class (java)

  25. 25

    Error: Could not find or load main class while class is included in the jar file

  26. 26

    Error: could not find or load main class in java

  27. 27

    Error: Could not find or load main class MyCSVParser

  28. 28

    Getting Error: Could not find or load main class while opening executable Jar file

  29. 29

    IntelliJ: Error: Could not find or load main class

HotTag

Archive