NoClassDefFoundError when ChartFactory.createXYLineChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
alvarbar
Posts: 4
Joined: Wed Feb 22, 2006 1:14 pm

NoClassDefFoundError when ChartFactory.createXYLineChart

Post by alvarbar » Wed Feb 22, 2006 1:25 pm

Hi, when executing a servlet that generates a chart I get the exception shown below. It's a java.lang.NoClassDefFoundError, but it does not specify which class it's not understanding. The version of jfreechart I'm using is 0.9.21 with jcommon 0.9.6, and the servlet is running on tomcat 3.3 (yes really old, but migration to a newer version is not possible right now, the application just stops working). The piece of code that causes the exception is:

JFreeChart chart =
ChartFactory.createXYLineChart("Demanda",
"Horas", "Nm3/hora", dataset,
PlotOrientation.VERTICAL,
true,true,false);

Any hint will be appreciated.
Thanks,
alvarbar


java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:58)
at java.awt.Font.initializeFont(Font.java:264)
at java.awt.Font.<init>(Font.java:298)
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:113)
at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)
at com.enagas.web.grafico.DemandaGrafico.crearChart(DemandaGrafico.java:76)
at com.enagas.web.grafico.DemandaGrafico.doGet(DemandaGrafico.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:484)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:432)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:213)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:477)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:519)
at java.lang.Thread.run(Thread.java:484)

javydreamercsw
Posts: 15
Joined: Fri Oct 07, 2005 2:32 pm

Post by javydreamercsw » Wed Feb 22, 2006 1:31 pm

The version you are using is not stable try upgrading first to version 1.0.1. From the error I can't do much to help. It might be servlet.jar missing?

alvarbar
Posts: 4
Joined: Wed Feb 22, 2006 1:14 pm

Post by alvarbar » Wed Feb 22, 2006 1:59 pm

Since the exception trace alerts:

at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)

I've searched thru the source code what happens in line 1285 of ChartFactory. That line is within the method createXYLineChart and it just instantiates a NumberAxis object:

NumberAxis xAxis = new NumberAxis(xAxisLabel);

This object is definitely included in the jar so I don´t know what else may work wrong.
Well, I'll try another version, but I don´t think is a version problem. Actually the application is drawing the graph fine in other computer with same version of tomcat and same version of jdk1.3.1 installed.

alvarbar
Posts: 4
Joined: Wed Feb 22, 2006 1:14 pm

Post by alvarbar » Wed Feb 22, 2006 2:03 pm

Well, actually there is an important difference between the computer where it is working ant the one it´s not working.
It works with Windows 2000
It´s not working on Linux (Debian)
Is it necessary to include any extras for jfreechart to work on linux?

javydreamercsw
Posts: 15
Joined: Fri Oct 07, 2005 2:32 pm

Post by javydreamercsw » Wed Feb 22, 2006 2:07 pm

Sadly my jfreechart experience is limited to Windows enviroments. Anyway the JVM's should be equivalet in both systems (Linux & Windows) based on the portability of JAVA. But it might need some tweaks in linux.

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Wed Feb 22, 2006 2:31 pm

Search for the "headless"-mode

alvarbar
Posts: 4
Joined: Wed Feb 22, 2006 1:14 pm

Post by alvarbar » Wed Feb 22, 2006 4:37 pm

I'm using jdk 1.3.1 and as far as I know, headless mode is not available for versions under 1.4

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Thu Feb 23, 2006 8:37 am

alvarbar wrote:I'm using jdk 1.3.1 and as far as I know, headless mode is not available for versions under 1.4
In this case search for "x11" or "xserver"

exo
Posts: 4
Joined: Tue Oct 31, 2006 1:49 am
Location: Israel

Re: NoClassDefFoundError when ChartFactory.createXYLineChart

Post by exo » Fri Mar 20, 2009 12:14 am

I just had the same problem when running on Linux. After spending an evening on this, I'd like to share my findings. There are three solutions I found:
1) If you don't need user interaction, e.g. just need to generate an image for a web application, you can run headless. So, set the java system property: java -Djava.awt.headless=true, can also be set inside the java code. Please refer to: http://java.sun.com/developer/technical ... /headless/ and make sure you don't use any of the mentioned classes.
2) Java 5 has a bug with locating its shared libraries. If you need to use JDK1.5, add $JAVA_HOME/lib/i386 to $LD_LIBRARY_PATH, e.g. setenv LD_LIBRARY_PATH {$JAVA_HOME/lib/i386:$LD_LIBRARY_PATH}.
3) Upgrade to Java 6.

Since my code has user interaction, the first solution didn't work (received HeadlessException of couse), but the other two work great.
Hope someone will find this helpful.

Locked