X11

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
superjma
Posts: 8
Joined: Sat Jun 14, 2003 12:15 pm

X11

Post by superjma » Sat Jun 28, 2003 7:21 pm

I got a Redhat 9 server without any X installed. I get an exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

I used these system.properties but this did not help:

Properties prop = System.getProperties ();
prop.put ("awt.toolkit", "com.eteks.awt.PJAToolkit");
prop.put ("java.awt.headless", "true");
System.setProperties (prop);

The command /usr/java/j2sdk1.4.1_01/bin/java -Djava.awt.headless=true grafdata do not work either.

I am running the program from the shell as root, because it is the plan that it should be run as a cron-job.

I do not have Tomcat installed but I do have Resin! (But the plan was only to generate a new JPEG once a week)

I installed the package compat-libstdc++-7.3-2.96.118.i386.rpm which solved one of my problems with libstdc++, but then I got an other one, X11!

I also tried to install the packages:
XFree86-xauth-4.3.0-2.i386.rpm
Glide3-20010520-25.i386.rpm
XFree86-base-fonts-4.3.0-2.i386.rpm
desktop-file-utils-0.3-5.i386.rpm
xinitrc-3.32-1.noarch.rpm
XFree86-4.3.0-2.i386.rpm

But this didn't help either!

Hope someone can help me...

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sun Jun 29, 2003 5:09 pm

Hi,

the PJA and headless properties must be set before Java is started to be sure that they get used. So start your app with:

/usr/java/j2sdk1.4.1_01/bin/java -Dawt.toolkit=com.eteks.awt.PJAToolkit ...

to use the PJA. Replacing the AWT at runtime is not possible, it has to be done before the AWT gets initialized.

The headless environment requires at least the x11 libs installed to work, once these libs are ok, the JDK should work.

You should never get the "java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable." error when the AWT is in headless mode. If you get it, then your AWT is not headless ...

Have more fun,
said Thomas

superjma
Posts: 8
Joined: Sat Jun 14, 2003 12:15 pm

Still problems

Post by superjma » Mon Jun 30, 2003 7:15 pm

It feels like it don't use this PJA property.

Code: Select all

[root@calm java]# /usr/java/j2sdk1.4.1_01/bin/java -Dawt.toolkit=com.eteks.awt.PJAToolkit grafdata
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:125)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:140)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
        at java.awt.Window.init(Window.java:223)
        at java.awt.Window.<init>(Window.java:267)
        at java.awt.Frame.<init>(Frame.java:398)
        at javax.swing.JFrame.<init>(JFrame.java:198)
        at org.jfree.ui.ApplicationFrame.<init>(Unknown Source)
        at grafdata.<init>(grafdata.java:18 )
        at grafdata.main(grafdata.java:68 )
I even included it in my source..

Code: Select all

import com.eteks.awt.*;
..
public static void main(String[] args) {
                //System.setProperty("java.awt.headless","true");
                Properties prop = System.getProperties ();
                prop.put ("awt.toolkit", "com.eteks.awt.PJAToolkit");
                prop.put ("java.awt.headless", "true");
                System.setProperties (prop);
        grafdata graf = new grafdata("Performance");
    }
I just can't figure out why it ain't working. Because I did as all other examples I found on the net. :(

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Mon Jun 30, 2003 7:26 pm

Hi,

you can never set the awt.toolkit property from within an programm. This is impossible and will show no effect at all. The same applies to the headless property.

These properties must be set outside when the VM is started.
Use the commandline ("java -D ... ") to define the properties. Anything else is useless ...

Have more fun,
said Thomas

superjma
Posts: 8
Joined: Sat Jun 14, 2003 12:15 pm

OK now I got a bit further

Post by superjma » Mon Jun 30, 2003 7:29 pm

I tried to use both -Dawt.toolkit=com.eteks.awt.PJAToolkit and -Djava.awt.headless=true. This resultet in some other errors.. but now it seems that it is using headless mode.

Then I included import java.awt.*; which solved some more problems.
Then I put a

Code: Select all

try{
			grafdata graf = new grafdata("Performance");
		}
		catch(Exception e){System.out.println(e.toString());}
in the main-thread.

This almost solved the problem. Now the problem is this Exception which says absolutely nothing about what is wrong!! (other than I still got problems with HEADLESS-mode)

Code: Select all

[root@calm java]# /usr/java/j2sdk1.4.1_01/bin/java -Dawt.toolkit=com.eteks.awt.PJAToolkit -Djava.awt.headless=true grafdata
java.awt.HeadlessException
Hope someone know what this is.. :?:

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Mon Jun 30, 2003 8:32 pm

Hi,

do you create frames or dialogs? Or one of the components listed here?

http://java.sun.com/j2se/1.4.1/docs/api ... ption.html

All of these methods throw headless exceptions, and you just crashed into one of them.

To find the evil method, change

Code: Select all

try{
         grafdata graf = new grafdata("Performance");
      }
      catch(Exception e){System.out.println(e.toString());}
to

Code: Select all

try{
         grafdata graf = new grafdata("Performance");
      }
      catch(Exception e){e.printStacktrace();}
This way you will see, where the exception occurs. It is always a good idea to use Exception.printStacktrace() instead of Exception.toString(), unless you are not interested where the bug is :)

Have more fun,
said Thomas

superjma
Posts: 8
Joined: Sat Jun 14, 2003 12:15 pm

Thanks.. but still problems

Post by superjma » Mon Jun 30, 2003 9:20 pm

I use frames I guess..

This is the constructor.. I'm not sure if it is possible to do without frames..

Code: Select all

public class grafdata extends ApplicationFrame {
public grafdata(String title) {
        super(title);
        TimeSeries portfolio= new TimeSeries("Portfolio", Day.class);
        TimeSeries kfx= new TimeSeries("KFX", Day.class);
        TimeSeries kax= new TimeSeries("KAX", Day.class);

		String url = "jdbc:mysql://localhost/aktier";
		String sql_user="webserver";
		String sql_pass="webserver";

		String sqlTxt="SELECT date, kfx_index, kax_index, p_index from performance";
		try{
			Class.forName("org.gjt.mm.mysql.Driver");
			ResultSet r=DriverManager.getConnection(url,sql_user,sql_pass).createStatement().executeQuery(sqlTxt);
			while(r.next()){
				String date=r.getString("date");
				portfolio.add(new Day(Integer.parseInt(date.substring(8,10)), Integer.parseInt(date.substring(5,7)), Integer.parseInt(date.substring(0,4))), r.getDouble("p_index"));
				kfx.add(new Day(Integer.parseInt(date.substring(8,10)), Integer.parseInt(date.substring(5,7)), Integer.parseInt(date.substring(0,4))), r.getDouble("kfx_index"));
				kax.add(new Day(Integer.parseInt(date.substring(8,10)), Integer.parseInt(date.substring(5,7)), Integer.parseInt(date.substring(0,4))), r.getDouble("kax_index"));
			}
		}
		catch(Exception e){System.out.println(e);}

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(portfolio);
        dataset.addSeries(kfx);
        dataset.addSeries(kax);

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Performance","Dato","Kurs",dataset,true,true,false);

		chart.setBackgroundPaint(java.awt.Color.white);

        // save it to an image
		try {
			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
			File file1 = new File("portfoliograf.jpg");
			ChartUtilities.saveChartAsJPEG(file1, chart, 556, 296, info);
		}
		catch (Exception e) {
			System.out.println(e.toString());
        }
    }
but I'm not sure how do I solve this Exception.. Because I might use frames but it is NOT dependent of keyboard or mouse or anything else.. I only use it for generating an image..

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Mon Jun 30, 2003 9:27 pm

Hi,

as far as I can see, you are not using any of the frames methods, so remove the "extends ApplicationFrame" and the call to the super class constructor and it should work ...

Your image is generated directly by using the saveChartAsJPEG method. This method is a static method of the class ChartUtilities and does not use or even know your class, and therefore this method does not depend on being called from a JFrame.

Have more fun,
said Thomas

Guest

Jah.. I just found out before you wrote..

Post by Guest » Mon Jun 30, 2003 10:24 pm

I just copied and pasted the content from the try in the constructor to the main-class and removed the things you said and it worked then..

Thanks a lot... :D

Locked