currentNode上的jcr Java空检查
我对爪哇很陌生,所以请容忍我。我有一小段代码 检查currentNode是否具有“fileReference”属性并返回其值。 但我的空检查似乎不起作用,因为如果fileReference中没有任何内容 我犯了个错误。如果存在对fileReference的引用,则可以正常工作。以下是错误:
Caused by: javax.jcr.PathNotFoundException: fileReference
这是我的代码:
if(currentNode != null){
NodeIterator checkNode = currentNode.getNodes();
while (checkNode.hasNext()) {
Node imageNode = checkNode.nextNode();
printNodeTitle = imageNode.getProperty("fileReference").getString();
}
}
public String getImageNode() { (printNodeTitle != null) ? return printNodeTitle : return ""; }
非常感谢您的帮助
# 1 楼答案
我不是{}方面的专家,但试试这个
如果找不到任何节点并且检索到空的
Iterator
,则使用getProperties(String)检索所有节点行
Node fileReference...
我刚刚猜到了类型(Node
),你必须改变它