You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Rob Outar <ro...@ideorlando.org> on 2002/10/28 21:13:05 UTC

Class Cast Exception

I am trying to upgrade to  Xerces 2, we are trying something very trivial
but it will not work:

import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;


/**
 * @testcase net.onesaf.services.data.xml.sax.TestSAX
 */
public class SAX {


    public SAX(){
        try {
            System.out.println("In here");
        XMLReader parser = XMLReaderFactory.createXMLReader(
     "org.apache.xerces.parsers.SAXParser");
   System.out.println("out here");
        }
        catch(Exception e){
   System.out.print(e);
        }
    }

but we keep getting a ClassCastException
In here

java.lang.ClassCastException

What are we doing wrong?

Thanks,

Rob

RE: Class Cast Exception

Posted by Rob Outar <ro...@ideorlando.org>.
Additional info, exception states:

SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement
XMLReader

which makes no sense.

Thanks,

Rob

 -----Original Message-----
From: Rishi Khanna [mailto:rishi@rishikhanna.com]
Sent: Monday, October 28, 2002 3:22 PM
To: xerces-j-user@xml.apache.org
Subject: Re: Class Cast Exception


  I haven't implemented this with XMLReaderFactory, but if you're willing to
try, you can load the class with the following code:

  XMLReader parser = (XMLReader)
Class.forName("org.apache.xerces.parsers.SAXParser").newInstance();


  ----- Original Message -----
    From: Rob Outar
    To: xerces-j-user@xml.apache.org
    Sent: Monday, October 28, 2002 3:13 PM
    Subject: Class Cast Exception


    I am trying to upgrade to  Xerces 2, we are trying something very
trivial but it will not work:

    import org.apache.xerces.parsers.SAXParser;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;


    /**
     * @testcase net.onesaf.services.data.xml.sax.TestSAX
     */
    public class SAX {


        public SAX(){
            try {
                System.out.println("In here");
            XMLReader parser = XMLReaderFactory.createXMLReader(
         "org.apache.xerces.parsers.SAXParser");
       System.out.println("out here");
            }
            catch(Exception e){
       System.out.print(e);
            }
        }

    but we keep getting a ClassCastException
    In here

    java.lang.ClassCastException

    What are we doing wrong?

    Thanks,

    Rob

Re: Class Cast Exception

Posted by Rishi Khanna <ri...@rishikhanna.com>.
I haven't implemented this with XMLReaderFactory, but if you're willing to try, you can load the class with the following code:

XMLReader parser = (XMLReader) Class.forName("org.apache.xerces.parsers.SAXParser").newInstance();


----- Original Message ----- 
  From: Rob Outar 
  To: xerces-j-user@xml.apache.org 
  Sent: Monday, October 28, 2002 3:13 PM
  Subject: Class Cast Exception


  I am trying to upgrade to  Xerces 2, we are trying something very trivial but it will not work:

  import org.apache.xerces.parsers.SAXParser;
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.XMLReaderFactory;


  /**
   * @testcase net.onesaf.services.data.xml.sax.TestSAX 
   */
  public class SAX {


      public SAX(){
          try {
              System.out.println("In here");
          XMLReader parser = XMLReaderFactory.createXMLReader(
       "org.apache.xerces.parsers.SAXParser");
     System.out.println("out here");
          }
          catch(Exception e){
     System.out.print(e);
          }
      }

  but we keep getting a ClassCastException
  In here

  java.lang.ClassCastException

  What are we doing wrong?

  Thanks,

  Rob