Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update a Pie Chart in Swing with embedded JavaFx applet - Null Point Exception
    primarykey
    data
    text
    <p>I'm working on my final programming task for school and wanted to add a piece of little functional eye candy to my java application, in the form of a dynamic Pie Chart in JavaFx. </p> <p>Using Netbeans 7.2 rc2, I created a swing/javafx hybrid application from the templates. I extended the JPanelClass to create a shell with which my main application could use to access the FX features. The problem I'm facing, however is that while the initialisation of the chart goes smoothly, when I try to update the blasted thing, it generates a Null Pointer Exception. Here I believe is the pertinent code:</p> <p><em>Instantiation:</em></p> <pre><code>public class PieChartJFxPanel extends JApplet { private static final int JFXPANEL_WIDTH_INT = 500; private static final int JFXPANEL_HEIGHT_INT = 500; StackPane root = new StackPane(); PieChart athleteChart; ObservableList&lt;PieChart.Data&gt; pieChartData =FXCollections.observableArrayList(); private static JFXPanel fxContainer; private int fAthletes=0; private int rAthletes=0; public PieChartJFxPanel(int totalAthletes,int finishedAthletes){ super(); fAthletes=finishedAthletes; rAthletes=totalAthletes-fAthletes; } @Override public void init() { fxContainer = new JFXPanel(); fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT)); add(fxContainer, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); } </code></pre> <p>The Scene Constructor:</p> <pre><code>private void createScene() { pieChartData.add(new PieChart.Data("Finished",fAthletes)); pieChartData.add(new PieChart.Data("Outstanding",rAthletes)); athleteChart=new PieChart(); athleteChart.setLegendVisible(false); athleteChart.setTitle("Race Status"); //athleteChart.setAnimated(true); athleteChart.setData(pieChartData); root.getChildren().add(athleteChart); fxContainer.setScene(new Scene(root)); // } </code></pre> <p>And the method which generated the exception:</p> <pre><code>public void setData(int total, int in){ final ObservableList&lt;PieChart.Data&gt; pieChartDat=FXCollections.observableArrayList(); pieChartDat.add(new PieChart.Data("Finished",fAthletes)); pieChartDat.add(new PieChart.Data("Outstanding",rAthletes)); athleteChart.setData(pieChartDat); } </code></pre> <p>And the exception:</p> <pre><code>Exception in thread "main" java.lang.NullPointerException at piechartjpanel.PieChartJFxPanel.setData(PieChartJFxPanel.java:95) at piechartjpanel.AthleteIOChart.setAthletes(AthleteIOChart.java:62) at piechartjpanel.Test.setter(Test.java:34) at piechartjpanel.Test.main(Test.java:48) </code></pre> <p>Any help is appreciated :) Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload