I'm currently working on a class which writes Values into CmsXmlContent and saves them as a file. I've got many variables and it's working very well but one String seems to hate me... It returns a NullPointerException everytime.
I tried to wrote it but seriously I'm checking if the String is null AND printing it out with perfect results just a line above.
So hopefully you can help me out :)
Expose:
public class Expose {
private String address, bid, build, corridorNumber, corridorPiece, county,
floor, form, houseType, mark, number, partner, price, registry,
roofAngle, size, status, title, view, width;
private List<String> features, infra, location, media, region, use,
useType;
private List<byte[]> documents, images;
private List<ExposeAbsatz> paragraphs;
// getters and setters
}
ExposeAbsatz:
public class ExposeAbsatz {
private String content, headline;
private byte[] image;
// getters and setters
}
My Code:
Locale de = Locale.GERMAN;
CmsXmlContent xmlContent = CmsXmlContentFactory.createDocument(cms,
de, "UTF-8", CmsXmlContentDefinition.getContentDefinitionForType(cms, "expose"));
if (StringUtils.isNotEmpty(thisExpose.getTitle()))
xmlContent.getValue("/titel", de).setStringValue(cms,
StringUtils.stripToEmpty(thisExpose.getTitle()));
// works
if (StringUtils.isNotEmpty(thisExpose.getNumber()))
xmlContent.getValue("/properties/number", de).setStringValue(
cms, StringUtils.stripToEmpty(thisExpose.getNumber()));
// works as well
if (thisExpose.getParagraphs() != null) {
int i = 0;
for (ExposeAbsatz currentExposeAbsatz : thisExpose.getParagraphs()) {
String headline = StringUtils.stripToEmpty(currentExposeAbsatz.getHeadline());
if (StringUtils.isNotEmpty(headline)) {
System.out.println("headline[" + i + "] = " + headline);
// headline[0] = aasd
// absatz is minOccurs="4" maxOccurs="5"
xmlContent.getValue("/absatz[" + i + "]/ueberschrift", de)
.setStringValue(cms, headline); // NullPointerException
(...)
}
(...)
i++;
}
}