hi, i m trying to draw a piechart using bufferedimage class using the following code
response.setContentType("image/png"); String[] slices = request.getParameterValues("slice"); String[] colors = request.getParameterValues("color"); int[] sizes = new int[slices.length]; Color[] cols = new Color[slices.length];
for(int i=0; i<slices.length; i++) { sizes[i] = Integer.parseInt(slices[i]); cols[i] = new Color(Integer.parseInt(colors[i],16)); } try{ int width = Integer.parseInt(request.getParameter("width")); int height = Integer.parseInt(request.getParameter("height")); Color background = new Color(Integer.parseInt(request.getParameter("background"),16)); BufferedImage buffer =new BufferedImage (width,height,BufferedImage.TYPE_INT_RGB); Graphics2D g2 = buffer.createGraphics(); g2.setColor(background); g2.fillRect(0,0,width,height); int arc = 0; for(int i=0; i<sizes.length; i++) { g2.setColor(cols[i]); g2.fillArc(0,0,width,height,arc,sizes[i]); arc += sizes[i]; } ServletOutputStream os = response.getOutputStream(); boolean flag=ImageIO.write(buffer, "png", os); } catch (Exception e){ } it gives following error at run time javax.servlet.ServletException: Servlet execution threw an exception at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain............................................................................................................
root cause
java.lang.NoClassDefFoundError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041) at pie.doGet(pie.java:53)...........................................................
can any body pls indicate what may b wrong. also if i comment the buffer.createGraphics code an image opens in photo shop showing a black rectangle. looking forward for some help regards khushi
Vijay Sharma
Ranch Hand
Joined: Feb 02, 2005
Posts: 32
posted
0
I think the problem is it is not able to find class definition,So,it's minor mistake.B'coz the code seems to be right.So, the problem is locating the jar file or package realted problem.Just update ur classpath for jar files also.
Hmm. I didn't know you could add it after the JVM had started. Glad it's working for you.
juilee rawale
Greenhorn
Joined: Aug 31, 2005
Posts: 7
posted
0
Hi, I am facing similar problem. I am trying to print from JSP to a shared printer. My application server JBOSS 3, printer and the client are on different linux advanced server 3 machines.
I am getting the exception
java.lang.NoClassDefFoundError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) at java.awt.Font.initializeFont(Font.java:308) at java.awt.Font.<init>(Font.java:344) at dm.web.reports.TextPage.<init>(Unknown Source) at dm.web.reports.TextFile.paginate(Unknown Source) at dm.web.reports.PrintReportUtil.printDocument(Unknown Source)
I tried using 1. setting JAVA_OPTS to -Djava.awt.headless=true in run.sh 2. calling System.setProperty( "java.awt.headless", "true" ); in jspInit() in my jsp but it didn't help!!!
This problem is not coming on Linux advanced server 4. But, I want to run it on Linux advanced server 3
Plzzzzzz help
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
posted
0
Originally posted by jui rawale: I am facing similar problem. I am trying to print from JSP to a shared printer. My application server JBOSS 3, printer and the client are on different linux advanced server 3 machines.
This is for you mate.
You can run Xvfb, the X virtual frame buffer, and then set DISPLAY=:1 in JBoss, I did for Tomcat though, environment. It's basically a mini X server. I've done this instead of using headless mode because headless was not working for me.