Roshani:

I'm not sure why you're getting this error. However, I will advise you not
to use the static 'Marshaller.marshal' method. It will not pick up your
mapping.xml file. You should instantiate your own mapping and marshall your
objects with code that looks something like this:

    private static org.exolab.castor.mapping.Mapping sMapping = null;

    private static synchronized void initMapping() throws Exception {
      sMapping = new org.exolab.castor.mapping.Mapping();
      String mappingUrl = "mapping.xml";
      sMapping.setBaseURL(mappingUrl);
      sMapping.loadMapping(mappingUrl);
    }

    private static void toXml(Object obj) throws Exception {
       if (sMapping == null) { initMapping(); }

      Marshaller converter = new Marshaller(new
java.io.PrintWriter(System.out));
      converter.setMapping(sMapping);

      converter.setMarshalAsDocument(addXmlTag);
        converter.marshal(object);
   }


----- Original Message -----
From: "Roshani Bhatt" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 17, 2001 10:28 AM
Subject: [castor-dev] Marshalling Error


| I have a 'Person' Class with one attribute -name.  I
| am trying to use the castor to create an xml file but
| I am getting the following error:
|
| Thread[main,5,main] (Alive): Uncaught exception
| (java.lang.ExceptionInInitializerError)
| ClassDescriptorResolverImpl()
| Marshaller.initialize()
| Marshaller(Writer)
| Marshaller.marshal(Object, Writer)
| Person.main(String [])
|
|
| Do you have any suggestions?  This is how my code
| looks:
|
| /package gov.test;
|
| import java.util.*;
| import java.io.IOException;
| import java.io.FileReader;
| import java.io.FileWriter;
| import java.io.OutputStreamWriter;
|
| import org.exolab.castor.mapping.Mapping;
| import org.exolab.castor.mapping.MappingException;
|
| import org.exolab.castor.xml.Unmarshaller;
| import org.exolab.castor.xml.Marshaller;
|
| import org.xml.sax.InputSource;
| public class Person implements java.io.Serializable
| {
|
|    /**
|      * The name of the person
|      */
|    private String name = "xxx";
|
|
|
| /**
|  * Person constructor comment.
|  */
| public Person() {
| super();
| }
|    /**
|      * Creates a Person with the given name
|      */
|    public Person(String name) {
|       this.name  = name;
|    }
|    /**
|      * @return name of the person
|      */
|    public String getName() {
|       return name;
|    }
| /**
|  * Insert the method's description here.
|  * Creation date: (10/16/01 1:31:04 PM)
|  * @param args java.lang.String[]
|  */
| public static void main(String[] args) {
|
| // Create a new Person
| Person person = new Person("Ryan 'Mad Dog' Madden");
|
|
| try{
| // Create a File to marshal to
| String filename = "D:\\test.xml";
| FileWriter writer = new FileWriter(filename);
|
| // Marshal the person object
| Marshaller.marshal(person, writer);
| }
| catch (Exception e)
| {System.out.println ("Marshall failed - RB");
| }
|
|
|
|
|
|
| }
|    /**
|      * Sets the name of the person
|      * @param name the name of the person
|      */
|    public void setName(String name) {
|       this.name = name;
|    }
| }
|
|
|
|
| __________________________________________________
| Do You Yahoo!?
| Make a great connection at Yahoo! Personals.
| http://personals.yahoo.com
|
| -----------------------------------------------------------
| If you wish to unsubscribe from this mailing, send mail to
| [EMAIL PROTECTED] with a subject of:
| unsubscribe castor-dev
|
|
|

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to