シリーズのsetTitleのためのapache-POI 4.0にNullPointer

チューチェン魏:

org.apache.poi.xddf.usermodel.chart.XDDFChartData $ Series.setTitleのスレッド "メイン" のjava.lang.NullPointerExceptionの例外(XDDFChartData.java:122)

コードは以下のように、次のとおりです。

CellReference cellref = new CellReference("A6"); 

//A6 value = "My Title"

XDDFLineChartData.Series series3 = (XDDFLineChartData.Series)data.addSeries(xs, ys3);
series3.setMarkerSize((short) 6);
series3.setMarkerStyle(MarkerStyle.DIAMOND);

series3.setTitle("My Title",cellref);

私はそれがために、文字列に必要な、ドキュメントを確認arg0し、CellReferenceためにarg1

私は終わる続けますNullPointerException私は何かが足りません?

回答いただきありがとうございます。

アクセル・リヒター:

のバグを修復する方法を疑問に答えるためにXDDFChartData.Series.setTitle

XDDFChartData.Series.setTitle getSeriesText()ヌルチェックなしで使用されています。しかしXDDFLineChartData.Series.getSeriesText()ので、当然のがnullを返すことがseries.getTx()nullを返す場合があります。だから我々は、一連のテキスト要素を使用する前にすでに存在していることを、確認してくださいする必要がXDDFChartData.Series.setTitle

...
XSSFChart chart = drawing.createChart(anchor);
...
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
...
XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
data.addSeries(...);
data.addSeries(...);
chart.plot(data);

if (chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getTx() == null) 
 chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).addNewTx();
data.getSeries().get(0).setTitle("Series 1 Title", null);

if (chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(1).getTx() == null)
 chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(1).addNewTx();
data.getSeries().get(1).setTitle("Series 2 Title", null);
...
//setting the axis Ids to the LineChart
chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(bottomAxis.getId());
chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(leftAxis.getId());
...

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=212709&siteId=1