我目前正在处理一个将值写入CmsXmlContent并将它们保存为文件的类。 我有很多变数而且工作得很好但是一个字符串似乎很讨厌我...... 它每次都返回一个NullPointerException。
我试着写它,但是我非常认真地检查String是否为空并将其打印出来,只有一行上面的完美结果。
所以希望你可以帮助我:)
揭露:
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
}
我的代码:
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++;
}
}