problem with jaxb

J

JCD

Hello.
i've created classes with xjc from that xml schema:
http://monique.damichel.perso.sfr.fr/provisoire/gpx.xml
Here's the list of those classes:
http://monique.damichel.perso.sfr.fr/provisoire/classesjaxb.gif

But when I compile that code:
JAXBContext jc = JAXBContext.newInstance("io.jaxb");
Unmarshaller unmarshaller = jc.createUnmarshaller();
GpxType gpx = (GpxType) unmarshaller.unmarshal(new FileInputStream
("ressources/BorneSN.gpx"));

I get that error message:
javax.xml.bind.JAXBElement cannot be cast to io.jaxb.GpxType
I don't know how to cast unmarshaller with the classes created by xjc
and I wonder if some are not missing.
What must I do? Please help me.
 
R

Robert Kochem

JCD said:
But when I compile that code:
JAXBContext jc = JAXBContext.newInstance("io.jaxb");
Unmarshaller unmarshaller = jc.createUnmarshaller();
GpxType gpx = (GpxType) unmarshaller.unmarshal(new FileInputStream
("ressources/BorneSN.gpx"));

I would do it this way:

JAXBContext jc = JAXBContext.newInstance(io.jaxb.GpxType.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
GpxType gpx = (GpxType) unmarshaller.unmarshal(new FileInputStream
("ressources/BorneSN.gpx"));

Robert
 
J

JCD

I would do it this way:

JAXBContext jc = JAXBContext.newInstance(io.jaxb.GpxType.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
GpxType gpx = (GpxType) unmarshaller.unmarshal(new FileInputStream
 ("ressources/BorneSN.gpx"));

Robert

Sorry but it doesn't work: I get the error message:
javax.xml.bind.JAXBElement cannot be cast to io.jaxb.GpxType
 
R

Robert Kochem

JCD said:
Sorry but it doesn't work: I get the error message:
javax.xml.bind.JAXBElement cannot be cast to io.jaxb.GpxType

The sample works fine with Java 1.6.0.15
Which Java / JAXB-version do you use?

Robert
 
J

JCD

The sample works fine with Java 1.6.0.15
Which Java / JAXB-version do you use?

Robert

I use Java SE 1.6 (it's all I know) and my ide is Eclipse. How can I
get the number of the version?
You've tested my own sample?
You have only 16 classes generated by xjc?
 
L

Lew

JCD said:
I use Java SE 1.6 (it's all I know) and my ide is Eclipse. How can I
get the number of the version?

"java -version"

You should read the documentation. It is your friend.

At the very least, you could have tried "java -help".
 
J

JCD

"java -version"

You should read the documentation.  It is your friend.

At the very least, you could have tried "java -help".

Robert, my version is 1.6.0.16.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,841
Latest member
WilmerBelg

Latest Threads

Top