Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JAXB - NullPointerException

15 views
Skip to first unread message

Piotr Porzucek

unread,
Jun 7, 2007, 5:50:33 PM6/7/07
to
Witam,

Na podstawie schematu XML wygenerowałem klasy poleceniem:
xjc -p xml.klasy company_database.xsd

Wywołując w aplikacji konsolowej:

JAXBContext jaxbContext = JAXBContext.newInstance("xml.klasy");

pojawia mi się wyjątek:

Exception in thread "main" java.lang.NullPointerException
at
com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:287)
at
com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:260)
at
com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.getTypes(ElementPropertyInfoImpl.java:100)
at
com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.getTypes(RuntimeElementPropertyInfoImpl.java:50)
at
com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.size(ElementPropertyInfoImpl.java:42)
at java.util.AbstractList$Itr.hasNext(AbstractList.java:416)
at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:139)
at
com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:49)
at
com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:41)
at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:189)
at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:204)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:352)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:350)
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:349)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:215)
at
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
at
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:368)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at testowanie1.Main.main(Main.java:31)

*Poniżej przedstawiam schemat XML company_database.xsd:*


<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:wyd="http://www.wydawnictwo.pl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.wydawnictwo.pl"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="image" type="xs:anyURI"/>
<xs:element name="description"/>
<xs:group ref="wyd:basic_book_data"/>
<xs:element name="available" type="xs:boolean"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="company">
<xs:complexType>
<xs:sequence>
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element ref="wyd:book" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="categories">
<xs:complexType>
<xs:sequence>
<xs:element name="category" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="BookId">
<xs:selector xpath="wyd:books/wyd:book"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="BookToCategory" refer="wyd:BookId">
<xs:selector xpath="wyd:categories/wyd:category/wyd:isbn"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
<xs:group name="basic_book_data">
<xs:sequence>
<xs:element name="price"/>
<xs:element name="title"/>
<xs:element name="author" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>
</xs:schema>


Co może być nie tak? Z góry dziękuje za pomoc.

Pozdrawiam,
Piotr Porzucek

Piotr Porzucek

unread,
Jun 7, 2007, 6:11:13 PM6/7/07
to

Poradziłem sobie - zamiast korzystać z bibliotek JAXB-a z JAX-WS
zainstalowem Java Web Services Developer Pack 2.0. Ale pojawił się nowy
wyjątek :/

Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected
element (uri:"http://www.wydawnictwo.pl", local:"company"). Expected
elements are <{}book>,<{}company>
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:556)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:199)


Dlaczego nie widzi przestrzeni nazw, skoro są zadeklarowane w schemacie?
Dla uzupełnienia podaje mój plik źródłowy xml:

<?xml version="1.0" encoding="UTF-8"?>

<company xmlns="http://www.wydawnictwo.pl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.wydawnictwo.pl
C:\DOCUME~1\piotr\Testowanie1\src\company_database.xsd">
<books>
<book id="ISBN83-7361-065-0">
<image></image>
<description></description>
<price>79.00</price>
<title>Oracle9i. Programowanie w języku PL/SQL</title>
<author>Scott Urman</author>
<available>true</available>
</book>
<book id="ISBN83-7361-750-7">
<image></image>
<description></description>
<price>149.00</price>
<title>Oracle Database 10g. Kompendium administratora</title>
<author>Kevin Loney</author>
<available>true</available>
</book>
<book id="ISBN978-83-246-0614-6">
<image></image>
<description></description>
<price>44.00</price>
<title>SQL dla SQL Server 2005. Wprowadzenie</title>
<author>Sikha Saha Bagui</author>
<author>Richard Walsh Earp</author>
<available>true</available>
</book>


</books>
<categories>
<category id="catBazyDanych" name="Bazy Danych">
<isbn>ISBN83-7361-065-0</isbn>
<isbn>ISBN83-7361-750-7</isbn>
<isbn>ISBN978-83-246-0614-6</isbn>
<isbn>ISBN83-7361-050-2</isbn>
<isbn>ISBN83-7361-231-9</isbn>
</category>
<category id="catProgramowanie" name="Programowanie">
<isbn>ISBN83-7361-050-2</isbn>
<isbn>ISBN83-246-0320-4</isbn>
<isbn>ISBN978-83-246-0755-6</isbn>
<isbn>ISBN978-83-246-0475-3</isbn>
<isbn>ISBN83-7197-984-3</isbn>
<isbn>ISBN83-7361-842-2</isbn>
</category>
<category id="catSieciKomputerowe" name="Sieci komputerowe">
<isbn>ISBN83-246-0375-1</isbn>
<isbn>ISBN83-246-0353-0</isbn>
<isbn>ISBN83-246-0474-X</isbn>
</category>
<category id="catHardware" name="Hardware">
<isbn>ISBN83-246-0319-0</isbn>
<isbn>ISBN83-7361-398-6</isbn>
<isbn>ISBN83-7361-802-3</isbn>
</category>
<category id="catGrafikaKomputerowa" name="Grafika komputerowa">
<isbn>ISBN978-83-246-0412-8</isbn>
</category>
</categories>
</company>

0 new messages