0
我們正在使用XContentBuilder如下它被投擲的NullPointerException空指針異常在當使用elasticsearch XContentBuilder用法
private int count=0;
public void outerCall(){
XContentBuilder contentBuilder = jsonBuilder();
contentBuilder.startObject();
contentBuilder.field("key1", "value1");
contentBuilder.field("key2", "value2");
innerCall(contentBuilder, 0);
contentBuilder.field("key3", "value3");
contentBuilder.close();
log.info("OUTER "+contentBuilder.string());
}
private XContentBuilder innerCall(XContentBuilder contentBuilder, int count2) throws Exception{
//XContentBuilder contentBuilder = jsonBuilder().startObject();
contentBuilder.startArray("specifications");
contentBuilder.startObject();
contentBuilder.field("key", "value");
if(count<2){
innerCall(contentBuilder, count++);
}
else{
contentBuilder.endObject().endArray().endObject();
return contentBuilder;
}
log.info(contentBuilder.string());
return contentBuilder;
}
這是示例代碼和歌廳NPE在 contentBuilder.field(「KEY3」,「值3」 ); (「key」,「value」);
如果嘗試調試代碼獲取NPE contentBuilder.field(「key」,「value」);
幫我解決這個問題..
安置自己的堆棧跟蹤。 – jay