I have downloaded the code for drawing a bar chart,
that has imported these packages
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;
import org.jfree.data.general.*;

on compiling on java 1.6 these packages are giving error.
What is the problem??

Dani AI

Generated

Most likely cause: the JFreeChart runtime libraries are not available to the Java compiler and JVM. As pointed out, the example source alone is not enough. The JFreeChart distribution normally ships one or more jars (older releases also include a companion JCommon jar); those jars must be part of your project libraries at both compile time and run time. was also right that the exact error text would pinpoint the problem type (missing class vs incompatible class version).

Practical steps that work in most setups:

  • Download the JFreeChart binary distribution (it contains the compiled jar(s) and a lib folder when applicable) or add JFreeChart as a dependency with your build tool.
  • Put the jar(s) into a project "lib" folder and add them to the IDE project libraries (Eclipse: Project Properties -> Java Build Path -> Libraries; NetBeans: Project -> Libraries -> Add JAR/Folder; IntelliJ: Project Structure -> Modules -> Dependencies -> + -> JARs).
  • For command-line builds, include those jars on the compile- and runtime classpaths. Use jar tf your-jfreechart.jar to confirm the expected packages/classes are present.

Troubleshooting notes:

  • ClassNotFoundException/NoClassDefFoundError = jar not on the runtime classpath.
  • UnsupportedClassVersionError = jar was compiled with a newer Java than the one you are running.
  • If errors continue, compare the jar contents and Java versions. Example code snippets from tutorials sometimes omit the library binaries; ensure you downloaded the full release rather than only sample source files.

Recommended Answers

All 4 Replies

Add the jar containing the jfreechart library in you class path by using the "-cp <path to jar>" argument while compiling as well as running your Java program

Well, posting the error might help. We can't read your screen from here you know.

how can I get the jar containing the jfreechart library. I haven't ever worked on this.plz help me

From the link that stephen84s posted in your other thread - the one to JFreeChart. Did you download it or just some example code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.