It's ok...his object is simple enough for the introspection.
The problem is using an Array as the root object. I'm working on a fix. --Keith "Dr. Hartmut Kocher" wrote: > > It looks like you forgot to set the Mapping object. > mm.setMapping(...); > > If you don't do that, the marshaller doesn't really know how to handle > classes. You either should add a mapping file and set it, or use the source > generator to generate your java classes from an XML schema. The latter is at > least my preferred way of doing this. > > Hope this helps > Dr. Hartmut Kocher > Leonberg > Germany > > -----Ursprungliche Nachricht----- > Von: Mark A. Sellers [mailto:[EMAIL PROTECTED]] > Gesendet: Dienstag, 23. April 2002 19:44 > An: [EMAIL PROTECTED] > Betreff: Re: [castor-dev] How do I marshall a collection of my class > objects? > > I tried using the CVS version and still get an NPE exception. Here's what > I'm doing: > > package rm.castor; > > import java.util.Date; > import java.util.*; > import java.sql.Timestamp; > import java.awt.*; > import java.awt.event.*; > import java.io.*; > import org.exolab.castor.xml.*; > import TestObject; > import org.xml.sax.ContentHandler; > import org.apache.xml.serialize.*; > > class Castor extends Frame { > > public Castor() { > addWindowListener(new WindowAdapter() { > public void windowClosing(WindowEvent e) { > dispose(); > System.exit(0); > } > }); > } > > public static void main(String args[]) { > System.out.println("Starting Castor..."); > Castor mainFrame = new Castor(); > mainFrame.setSize(400, 400); > mainFrame.setTitle("Castor"); > mainFrame.setVisible(true); > > TestObject[] to = new TestObject[2]; > to[0] = new TestObject(); > to[0].setDateOfBirth(new java.util.Date("10/1/2001")); > to[0].setName("Mark"); > to[1] = new TestObject(); > to[1].setDateOfBirth(new java.util.Date("12/21/1956")); > to[1].setName("Sandy"); > > try { > FileWriter writer = new FileWriter("C:\\Castor\\cc.xml"); > Marshaller mm = new Marshaller(writer); > mm.setNamespaceMapping("-//EXOLAB/Castor Object Mapping Schema Version > 1.0//EN","http://castor.exolab.org/mapping.xsd"); > mm.setMarshalAsDocument(true); > mm.setValidation(false); > mm.setNSPrefixAtRoot(true); > > mm.marshal(to, writer); > > System.err.println("finished marshalling..."); > > } catch (java.io.IOException ioe) { > System.err.println(ioe.toString()); > } catch ( org.exolab.castor.xml.MarshalException me ) { > System.err.println(me.toString()); > } catch ( org.exolab.castor.xml.ValidationException ve ) { > System.err.println(ve.toString()); > } > } > } > > Class TestObject: > > import java.util.Date; > public class TestObject implements java.io.Serializable { > private String name = null; > private Date dob = null; > > public TestObject() { > super(); > } > > public TestObject(String name) { > this.name = name; > } > > public Date getDateOfBirth() { > return dob; > } > > public String getName() { > return name; > } > > public void setDateOfBirth(Date dob) { > this.dob = dob; > } > > public void setName(String name) { > this.name = name; > } > } > > Exception in thread "main" java.lang.NullPointerException > at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:672) > at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:540) > at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:460) > at rm.castor.Castor.main(Castor.java:160) > > Thanks, Mark Sellers > > ----------------------------------------------------------- > 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 ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
