Loading ...
Sorry, an error occurred while loading the content.
 

java.lang.NullPointerException

Expand Messages
  • Rajiv Bhattacharya
    Hi, i had submitted the pst yesterday.But i didnt get a single reply,although there are a lots of people with experiance on this group.So i thought of sending
    Message 1 of 1 , Jul 14, 2005
      Hi,
      i had submitted the pst yesterday.But i didnt get a single
      reply,although there are a lots of people with experiance on this
      group.So i thought of sending a more well documented post :-).Please
      try to help me if you can.
      here it goes..

      Im trying to run a application Transfer.java which uses a middleware
      XML-DBMS to transfer XML data to the Oracle database.Transfer.java
      compiles without any errors but when i try to run it it gives the
      'java.lang.NullPointerException'.I dont know what to change in the
      code.the code is as follows

      ---------------------------------------------------------------------------------------
      hi,
      Im trying to run a application Transfer.java which uses a middleware
      XML-DBMS to transfer XML data to the Oracle database.Transfer.java
      compiles without any errors but when i try to run it it gives the
      'java.lang.NullPointerException'.I dont know what to change in the
      code.the code is as follows

      ---------------------------------------------------------------------------------------
      import de.tudarmstadt.ito.xmldbms.DOMToDBMS;
      import de.tudarmstadt.ito.xmldbms.Map;
      import de.tudarmstadt.ito.xmldbms.helpers.KeyGeneratorImpl;
      import de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument;

      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.OutputStream;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import org.xml.sax.InputSource;
      import org.xml.sax.Parser;
      import org.w3c.dom.Document;

      // Imports for the Xerces parser
      import de.tudarmstadt.ito.domutils.DF_Xerces;
      import de.tudarmstadt.ito.domutils.NQ_DOM2;
      import org.apache.xerces.parsers.DOMParser;
      import org.apache.xerces.parsers.SAXParser;
      import org.apache.xml.serialize.OutputFormat;
      import org.apache.xml.serialize.XMLSerializer;

      public class Transfer
      {

      // Main methods
      public static void main (String[] argv)
      {
      String mapFilename = null,
      xmlFilename = null,
      url = "jdbc:oracle:thin:@97.253.1.39:1521:rdn_ov";
      try
      {
      if (argv.length < 2) throw new IllegalArgumentException();

      mapFilename = argv[0];
      xmlFilename = argv[1];

      toDBMS(mapFilename, xmlFilename, url); //ERROR HERE

      }
      catch (IllegalArgumentException iae)
      {
      System.out.println("\nUsage: java Transfer <map-file>
      <xml-file> \n");
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }


      static void toDBMS(String mapFilename, String xmlFilename, String url)
      throws Exception
      {
      Connection conn1 = null, conn2 = null;
      Map map;
      Document doc;
      DOMToDBMS domToDBMS;
      KeyGeneratorImpl keyGenerator = null;

      try
      {
      // Get the JDBC driver.
      Class.forName("oracle.jdbc.driver.OracleDriver");

      // Connect to the database.
      conn1 = DriverManager.getConnection(url,"project","project");
      conn2 = DriverManager.getConnection(url,"project","project");

      // Create and initialize a key generator
      keyGenerator = new KeyGeneratorImpl(conn1);
      keyGenerator.initialize();

      // Create the Map object and open the XML document.
      map = createMap(mapFilename, conn2);
      //ERROR HERE
      doc = openDocument(xmlFilename);

      // Create a new DOMToDBMS object and transfer the data.
      domToDBMS = new DOMToDBMS(map, keyGenerator, new NQ_DOM2());
      domToDBMS.storeDocument(doc);
      }
      finally
      {
      if (conn1 != null) conn1.close();
      if (conn2 != null) conn2.close();
      }
      }

      // General utility methods

      static Map createMap(String mapFilename, Connection conn) throws
      Exception
      {
      MapFactory_MapDocument factory;

      // Create a new map factory and create the Map.
      factory = new MapFactory_MapDocument(conn, getSAXParser());
      return factory.createMap(new
      InputSource(getFileURL(mapFilename))); //ERROR HERE
      }

      static String getFileURL(String fileName)
      {
      File file;

      file = new File(fileName);
      return "file:///" + file.getAbsolutePath();
      }


      // Methods that use the Xerces parser

      static Parser getSAXParser()
      {

      return new SAXParser();
      }

      static Document openDocument(String xmlFilename) throws Exception
      {


      DOMParser parser;

      // Instantiate the parser and set various options.
      parser = new DOMParser();
      parser.setFeature("http://xml.org/sax/features/namespaces", true);

      // Parse the input file
      parser.parse(new InputSource(getFileURL(xmlFilename)));

      // Return the DOM tree
      return parser.getDocument();
      }

      static void writeDocument(Document doc, String xmlFilename) throws
      Exception
      {
      FileOutputStream xmlFile;
      OutputFormat format;
      XMLSerializer serial;

      // Write the DOM tree to a file.
      xmlFile = new FileOutputStream(xmlFilename);
      format = new OutputFormat(doc);
      format.setIndenting(true);
      serial = new XMLSerializer((OutputStream)xmlFile, format);
      serial.asDOMSerializer().serialize(doc);
      xmlFile.close();
      }

      }


      ----------------------------------------------------
      and when i try to run the program at the command line using
      java Transfer order.map order.xml

      i get the following error
      java.lang.NullPointerException
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.processColumn(MapFactory_MapDocument.java:771)
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.startElement(MapFactory_MapDocument.java:423)
      at
      org.apache.xerces.parsers.SAXParser.startElement(SAXParser.java:1340)
      at
      org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1284)
      at
      org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806)
      at
      org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1182)
      at
      org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      at
      org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.createMap(MapFactory_MapDocument.java:311)
      at Transfer.createMap(Transfer.java:99)
      at Transfer.toDBMS(Transfer.java:77)
      at Transfer.main(Transfer.java:40)
      de.tudarmstadt.ito.xmldbms.InvalidMapException
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.createMap(MapFactory_MapDocument.java:326)
      at Transfer.createMap(Transfer.java:99)
      at Transfer.toDBMS(Transfer.java:77)
      at Transfer.main(Transfer.java:40)
      ------------------------------------------------------------
      i know that a null pointer exception happens when you have a variable
      that hasn't been assigned to a specific object yet.
      but i dont know what to change in the Transfer.java code.but i think
      the last three lines of the error can give a clue to an experianced
      eye.please help me as i am stuck with this error for a long time.I
      have indicated these lines by comment //ERROR HERE in the code .
      Thanks,
      -Rajiv

      ----------------------------------------------------
      and when i try to run the program at the command line using
      java Transfer order.map order.xml

      i get the following error
      java.lang.NullPointerException
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.processColumn(MapFactory_MapDocument.java:771)
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.startElement(MapFactory_MapDocument.java:423)
      at
      org.apache.xerces.parsers.SAXParser.startElement(SAXParser.java:1340)
      at
      org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1284)
      at
      org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806)
      at
      org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1182)
      at
      org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      at
      org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.createMap(MapFactory_MapDocument.java:311)
      at Transfer.createMap(Transfer.java:99)
      at Transfer.toDBMS(Transfer.java:77)
      at Transfer.main(Transfer.java:40)
      de.tudarmstadt.ito.xmldbms.InvalidMapException
      at
      de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_MapDocument.createMap(MapFactory_MapDocument.java:326)
      at Transfer.createMap(Transfer.java:99)
      at Transfer.toDBMS(Transfer.java:77)
      at Transfer.main(Transfer.java:40)
      ------------------------------------------------------------
      i know that a null pointer exception happens when you have a variable
      that hasn't been assigned to a specific object yet.
      but i dont know what to change in the Transfer.java code.but i think
      the last three lines of the error can give a clue to an experianced
      eye.please help me as i am stuck with this error for a long time.I
      have indicated these lines by comment //ERROR HERE in the code .
      Thanks,
      -Rajiv
    Your message has been successfully submitted and would be delivered to recipients shortly.