problem with jaxb

Discussion in 'Java' started by JCD, Oct 3, 2009.

  1. JCD

    JCD Guest

    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.
     
    JCD, Oct 3, 2009
    #1
    1. Advertisements

  2. 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
     
    Robert Kochem, Oct 3, 2009
    #2
    1. Advertisements

  3. JCD

    JCD Guest

    Sorry but it doesn't work: I get the error message:
    javax.xml.bind.JAXBElement cannot be cast to io.jaxb.GpxType
     
    JCD, Oct 3, 2009
    #3
  4. The sample works fine with Java 1.6.0.15
    Which Java / JAXB-version do you use?

    Robert
     
    Robert Kochem, Oct 4, 2009
    #4
  5. JCD

    JCD Guest

    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?
     
    JCD, Oct 4, 2009
    #5
  6. JCD

    Lew Guest

    "java -version"

    You should read the documentation. It is your friend.

    At the very least, you could have tried "java -help".
     
    Lew, Oct 4, 2009
    #6
  7. JCD

    JCD Guest

    Robert, my version is 1.6.0.16.
     
    JCD, Oct 4, 2009
    #7
  8. JCD

    Lew Guest

    1.6.0_16
     
    Lew, Oct 4, 2009
    #8
  9. JCD

    JCD Guest

    Thank you very much for your answer Lew. But what's the problem with
    jaxb and my sample?
     
    JCD, Oct 4, 2009
    #9
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.