Reputation: 1
I tried creating a simple BarChart using JFreeChart. The code seems have no problem until I run it. The error message i got:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset
at test.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.category.CategoryDataset
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 1 more
Here's my code, given that I have a main class to call the ChartBar():
package chart;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class ChartBar extends JFrame{
private DefaultCategoryDataset dataset;
private JFreeChart chart;
private CategoryPlot categoryPlot;
private ChartPanel chartPanel;
public ChartBar() {
dataset = new DefaultCategoryDataset();
dataset.addValue(200, "Viet Nam", "2000");
//create chart
chart = ChartFactory.createBarChart("T la chung m", "", "Ty do", dataset, PlotOrientation.VERTICAL, true, true, false);
categoryPlot = chart.getCategoryPlot();
chartPanel = new ChartPanel(chart);
getContentPane().removeAll();
getContentPane().add(chartPanel, BorderLayout.CENTER);
// getContentPane().validate();
}
}
I search up and do everything i can, I'm very sure I've included the library in classpath. And the JFreeChart is the latest version. I can even see the "CategoryDataset" class in my explorer....
Upvotes: 0
Views: 29