錯誤顯示爲,我的XChartPanel構造函數(Java Swing)有什麼問題?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.knowm.xchart.internal.chartpart.Legend_AxesChart.paint(Legend_AxesChart.java:195)
at org.knowm.xchart.XYChart.paint(XYChart.java:254)
at org.knowm.xchart.XYChart.paint(XYChart.java:225)
at org.knowm.xchart.XChartPanel.paintComponent(XChartPanel.java:95)
at javax.swing.JComponent.paint(JComponent.java:1056)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5219)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495)
這裏是我的代碼,其中xyChart被聲明爲一個字段。我確信這是XChartPanel的構造器部分錯誤,但我根本不知道從哪裏開始。
/**
* Initialize the XYChart
*/
private void initXYChart() {
// Create Chart
xyChart = new XYChartBuilder().width(800).height(800).title(getClass().getSimpleName())
.xAxisTitle(xColName)
.yAxisTitle("Y").build();
// Customize Chart
xyChart.getStyler().setLegendPosition(LegendPosition.InsideNE);
xyChart.getStyler().setAxisTitlesVisible(true);
xyChart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Line);
double[] yCoordArray = new double[xCoordArray.length];
// Loop through the series
if (!seriesList.isEmpty()) {
for (int i = 0; i < yCoordinates.size(); i++) {
List<Double> yCoordOneSeries = yCoordinates.get(i);
// Convert list to array
for (int j = 0; j < yCoordArray.length; j++) {
yCoordArray[j] = yCoordOneSeries.get(j);
}
xyChart.addSeries(yColNames.get(i), xCoordArray, yCoordArray);
}
}
xyChartPanel = new XChartPanel<>(xyChart);
add(xyChartPanel, BorderLayout.CENTER);
}
我們可以看到你的繪畫方法嗎? – Natecat
我寫了沒有繪製方法,我試圖使用XChart。 – xxx222
試着自己找零null – Natecat