Search code examples
javajfreechart

JFreeChart Null Pointer issue


I'm just trying to run a demo of a 'simple' pie chart I found online. I'm running this in Eclipse Kepler and I keep getting,

Exception in thread "main" java.lang.NullPointerException
    at org.apache.fontbox.afm.AFMParser.main(AFMParser.java:304)

when I try to run the program. I would think, considering where I got the code (linked off of a JChart site), that it would run without issue. Just trying to see if anyone can see something I can't.

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

public class BarChartDemo {
    public static void main(String[] args){
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Category 1", 50.0);
        dataset.setValue("Category 2", 50.0);
        JFreeChart chart = ChartFactory.createPieChart(
            "Sample Pie Chart",
            dataset,
            true,
            true,
            false
            );

        ChartFrame frame = new ChartFrame("First",chart);
        frame.pack();
        frame.setVisible(true);
    }
}

Solution

  • After some battling and researching (guessing), I came across this class via some Adobe Font Metrics googling. Incidentally I can't remember exactly where I found it, but it solved my issue. I'll spare the SO servers and not post the 1000(+)-line code, but here it is as a gist if anyone has the same problem. I just included it in my project source file as a separate class, and voila...

    I'm still not sure why my project wouldn't run without this. It worked on other systems, but not my Eclipse Kepler (Mac OS 10.9). If anyone can tell me exactly why it kept failing, I'd be very thankful.