|
From: Ashley T. <at...@uk...> - 2004-01-03 13:25:15
|
Im having problems with this X11 (Unix based problem). Basically i got =
the code working on windows but not solaris, i've tried the=20
try{ System.setProperty("java.awt.headless","true");}catch( Throwable =
throwable ){}
fix but it doesn't seem to be working, im not sure if i've got it in the =
wrong place or if i've done it wrong or what? Its a servlet running on =
Sun One WebServer so i can't run it from the command line and thus add =
the -D<thingy>
any one any ideas???
i've got the code:
import org.jCharts.chartData.ChartDataException;
import org.jCharts.chartData.PieChartDataSet;
import org.jCharts.encoders.ServletEncoderHelper;
import org.jCharts.nonAxisChart.PieChart2D;
import org.jCharts.properties.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.awt.*;
import java.io.IOException;
public class PieChart2DServlet extends HttpServlet
{
//---all of my pie charts serviced by this Servlet will have the same =
properties.
private PieChart2DProperties properties;
private LegendProperties legendProperties;
private ChartProperties chartProperties;
private int width =3D 550;
private int height =3D 350;
=
/************************************************************************=
**********************
*
=
*************************************************************************=
*********************/
public void init()
{
// Solaris code to prevent X11 Server errors
try{ =
System.setProperty("java.awt.headless","true");}catch( Throwable =
throwable ){}
=20
//---all charts of this type of pie chart are going to =
share the same properties.
this.properties =3D new PieChart2DProperties();
this.legendProperties =3D new LegendProperties();
this.legendProperties.setNumColumns( 2 );
this.legendProperties.setPlacement( LegendProperties.RIGHT );
this.chartProperties =3D new ChartProperties();
}
=
/************************************************************************=
**********************
*
=
*************************************************************************=
*********************/
public void service( HttpServletRequest req, HttpServletResponse =
response ) throws ServletException, IOException
{
=20
=20
=20
=20
try
{ =20
PieChart2D pieChart2D =3D new PieChart2D( this.getData(req), =
this.legendProperties, this.chartProperties, this.width, this.height );
ServletEncoderHelper.encodeJPEG13( pieChart2D, 1.0f, response );
}
catch( Throwable throwable )
{
//HACK do your error handling here...
throwable.printStackTrace();
}
}
=
/************************************************************************=
******************
* Returns a Tests a 'real' data set and usage.
*
* @throws ChartDataException
=
*************************************************************************=
*****************/
private PieChartDataSet getData(HttpServletRequest req) throws =
ChartDataException
{
=20
String []y =3D req.getParameterValues("y");
// Defines the data
double[] data =3D new double[y.length];
=20
for (int i =3D0; i < y.length; i++){
Double d =3D (Double) Double.valueOf(y[i]);
data[i] =3D (double) d.doubleValue();
}
=20
// Defines the paints
Paint[] paints =3D new Paint[data.length];
for (int i =3D 0; i < paints.length; i++){
paints[i] =3D possible_paints[i];
} =20
=20
// Defines labels for each value
String[] labels =3D req.getParameterValues("x");
=20
// Defines the title=20
String title =3D "";
title =3D req.getParameter("title");
=20
return new PieChartDataSet(title, data, labels, paints, =
this.properties );
}
=20
// Defines the possible_paints MAX 9
private Paint[] possible_paints =3D new Paint[]{Color.blue,=20
Color.red,=20
Color.green,=20
Color.yellow,=20
Color.white,
Color.gray,
Color.orange,
Color.pink,
Color.blue,=20
Color.red,=20
Color.green,=20
Color.yellow,=20
Color.white,
Color.gray,
Color.orange,
Color.pink,
Color.blue};
}
im getting the errors:
[19/Dec/2003:08:12:18] failure (13591): Internal error: Unexpected =
error condition thrown (unknown exception,no description), stack: =
java.lang.InternalError: Can't connect to X11 window server using ':0.0' =
as the value of the DISPLAY variable.=20
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)=20
at =
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:125) =
at java.lang.Class.forName0(Native Method)=20
at java.lang.Class.forName(Class.java:140)=20
at =
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironm=
ent.java:62)=20
at java.awt.Font.initializeFont(Font.java:303)=20
at java.awt.Font.<init>(Font.java:339)=20
at org.jCharts.properties.util.ChartFont.<clinit>(Unknown Source)=20
at org.jCharts.properties.PieChart2DProperties.<init>(Unknown Source)=20
at PieChart2DServlet.init(PieChart2DServlet.java:30)=20
at javax.servlet.GenericServlet.init(GenericServlet.java:258)=20
at =
com.iplanet.server.http.servlet.NSServletEntity.load(NSServletEntity.java=
:405)=20
at =
com.iplanet.server.http.servlet.NSServletEntity.update(NSServletEntity.ja=
va:173)=20
at =
com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.j=
ava:416)
[02/Jan/2004:10:31:45] failure (23997): Internal error: Unexpected =
error condition thrown (unknown exception,no description), stack: =
java.lang.NoClassDefFoundError: sun/io/ByteToCharEUC_KR=20
at sun.awt.font.NativeFontWrapper.registerFonts(Native Method)=20
at =
sun.java2d.SunGraphicsEnvironment.addPathFonts(SunGraphicsEnvironment.jav=
a:736)=20
at =
sun.java2d.SunGraphicsEnvironment.registerFonts(SunGraphicsEnvironment.ja=
va:587)=20
at =
sun.java2d.SunGraphicsEnvironment.access$100(SunGraphicsEnvironment.java:=
49)=20
at =
sun.java2d.SunGraphicsEnvironment$2.run(SunGraphicsEnvironment.java:209) =
at java.security.AccessController.doPrivileged(Native Method)=20
at =
sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:2=
03)=20
at =
sun.java2d.SunGraphicsEnvironment.initTerminalNames(SunGraphicsEnvironmen=
t.java:1029)=20
at =
sun.java2d.SunGraphicsEnvironment.initCompositeFonts(SunGraphicsEnvironme=
nt.java:795)=20
at =
sun.java2d.SunGraphicsEnvironment.access$200(SunGraphicsEnvironment.java:=
49)=20
at =
sun.java2d.SunGraphicsEnvironment$1.run(SunGraphicsEnvironment.java:160) =
at java.security.AccessController.doPrivileged(Native Method)=20
at =
sun.java2d.SunGraphicsEnvironment.<init>(SunGraphicsEnvironment.java:78) =
at =
sun.awt.X11GraphicsEnvironment.<init>(X11GraphicsEnvironment.java:150)=20
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native =
Method)=20
at =
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAc=
cessorImpl.java:39)=20
at =
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConst=
ructorAccessorImpl.java:27)=20
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)=20
at java.lang.Class.newInstance0(Class.java:306)=20
at java.lang.Class.newInstance(Class.java:259)=20
at =
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironm=
ent.java:62)=20
at java.awt.Font.initializeFont(Font.java:303)=20
at java.awt.Font.<init>(Font.java:339)=20
at org.jCharts.properties.util.ChartFont.<clinit>(Unknown Source)=20
at org.jCharts.properties.PieChart2DProperties.<init>(Unknown Source)=20
at PieChart2DServlet.init(PieChart2DServlet.java:30)=20
at javax.servlet.GenericServlet.init(GenericServlet.java:258)=20
at =
com.iplanet.server.http.servlet.NSServletEntity.load(NSServletEntity.java=
:405)=20
at =
com.iplanet.server.http.servlet.NSServletEntity.update(NSServletEntity.ja=
va:173)=20
at =
com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.j=
ava:416) |