Thank you for the reply.
Here are java classes(I removed irrelevant fields and methods)
public class Resources {
private List<Resource> resource;
public Resources(List<Resource> resourceList) {
this.resource = resourceList;
}
public Resources(){
super();
}
public List<Resource> getResource() {
return resource;
}
public void setResource(List<Resource> resource) {
this.resource = resource;
}
}
public class Resource {
private List<String> fileNames;
private List<File> files;
/**
* Convenient method to conver files into String
* @param files
* @return
*/
private List<String> convertFileNames(List<File> files){
List<String> names = new ArrayList<String>();
if(files == null){
return names;
}
for(File file : files){
names.add(file.getAbsoluteFile());
}
return names;
}
//
-------------------------------------------------------------------------
// Mutator Methods
//
-------------------------------------------------------------------------
public String getFileNames() {
if(fileNames != null){
return fileNames;
}
else{
return convertFileNames(files);
}
}
public void setFileNames(String fileNames) {
this.fileNames = fileNames;
}
public void setFiles(List<File> files) {
this.files = files;
setFileNames(convertFileNames(files));
}
}
I don't initialize the outer List Resources.resource. If I remove the inner
Resource.fileNames, it works. So I would've thought it does not require
initialization? And from some examples I googled, they don't initialize List
either. But none of them uses nested collection tho...
Thanks and regards,
Patrick
Werner Guttmann-6 wrote:
>
> Hi,
>
> to give you a precise answer, you'd need to show us the Java code as well.
>
> Still, within your Resources/Resource classes, do you initialize the
> lists of resource/fileNames members upon object construction ?
>
> I.e. how do you declare the property fielNames in class Resource ?
>
> private List<String> filenames;
>
> or
>
> private List<String> filenames = new ArrayList<String>();
>
> Cheers
> Werner
>
> On 16.12.2009 00:34, patrickh wrote:
>>
>> Hi,
>>
>> I am trying to unmarshall a xml which is produced by castor.
>> I tried both having and not having mapping files and it all failed to
>> unmarshal.
>> Here is the xml:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <resources>
>> <resource>
>> <resource-file>fake address 1</resource-file>
>> <description-name>spiderman</description-name>
>> <time-of-creation>2009-10-10</time-of-creation>
>> <owner>huangp</owner>
>> <comment>good one</comment>
>> <category>category 1</category>
>> <size>1g</size>
>> <file-names>spiderman1.rmvb</file-names>
>> <file-names>spiderman2.rmvb</file-names>
>> </resource>
>> <resource>
>> <resource-file>fake address 2</resource-file>
>> <description-name>superman</description-name>
>> <time-of-creation>2009-10-11</time-of-creation>
>> <owner>huangp</owner>
>> <comment>bad one</comment>
>> <category>category 1</category>
>> <size>200m</size>
>> <file-names>superman a.rmvb</file-names>
>> <file-names>superman b.rmvb</file-names>
>> </resource>
>> </resources>
>>
>> Here is the mapping:
>> <class name="huangp.domain.Resource">
>> <map-to xml="resource" />
>> <field name="resourceFile" type="string" />
>> <field name="descriptionName" type="string" />
>> <field name="timeOfCreation" type="string" />
>> <field name="owner" type="string" />
>> <field name="comment" type="string" />
>> <field name="category" type="string" />
>> <field name="size" type="string" />
>> <field name="fileNames" type="string" collection="arraylist">
>> <bind-xml name="file-names" />
>> </field>
>> </class>
>>
>> <!-- mapping for class 'huangp.domain.Resources' -->
>> <class name="huangp.domain.Resources">
>> <field name="resource" type="huangp.domain.Resource"
>> collection="arraylist">
>> <bind-xml name="resource" />
>> </field>
>> </class>
>>
>> Exception trace:
>> org.exolab.castor.xml.MarshalException: Nested error:
>> java.lang.NullPointerException{File: [not available]; line: 11; column:
>> 43}
>>
>> Resources class only have one field which is a List<Resource>. Resource
>> class has detailed fields and it contains another List<String> fileNames.
>> I
>> suspect it is to do with this nested list? Can anyone please help? BTW I
>> can't access castor site since yesterday...
>>
>> Big thank you.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>
--
View this message in context:
http://old.nabble.com/getting-NullPointerException-with-nested-list-tp26803517p26820630.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email