LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-11-2004, 03:20 PM   #1
Cand1e
LQ Newbie
 
Registered: Feb 2004
Location: Location, Location.
Distribution: Debian / XP
Posts: 6

Rep: Reputation: 0
java Graphics[2D] requires an X server?


java Graphics[2D] requires an X server?

Code:
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>(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(Unknown Source)
        at java.awt.image.BufferedImage.createGraphics(Unknown Source)
        at (my code)
        at (my code)
        at (my code)
The line code that throws this exception is either
Code:
Graphics2D g = (Graphics2D)b.getGraphics();
or
Code:
Graphics2D g = b.createGraphics();
I have a linux box on which I would like to generate some images for use on a website, it doesn't have a X server - because a) it is only a P100 with a 1Gb HD, so the space required, and the processing power required for the X server are lacking! and b) the only cables out of the box are power and network... i.e. no moniter/k-b/etc

it is running Suns JVM on a debian base.

how can I resolve this issue - other than killing my machine with an X-server

the true Candle!
 
Old 02-11-2004, 03:23 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Well you are going to have to have an xserver to use any of the awt or swing functionality.
 
Old 02-11-2004, 03:26 PM   #3
Cand1e
LQ Newbie
 
Registered: Feb 2004
Location: Location, Location.
Distribution: Debian / XP
Posts: 6

Original Poster
Rep: Reputation: 0
is there a way round it?

and why does it need an X server? it doesn't make sense, all I want to do is write images to file, not display them or anything!
 
Old 02-11-2004, 04:17 PM   #4
dave bean
Member
 
Registered: Jun 2003
Location: UK
Distribution: Slackware 9.1
Posts: 136

Rep: Reputation: 15
did you just install java recently ? i had an almost identical error for non root users when their path wasn't set correctly
 
Old 02-11-2004, 07:20 PM   #5
Cand1e
LQ Newbie
 
Registered: Feb 2004
Location: Location, Location.
Distribution: Debian / XP
Posts: 6

Original Poster
Rep: Reputation: 0
it works fine on a Windows machine, just not the Linux P100. java is not a recent install, and it is in the path
 
Old 02-11-2004, 07:38 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
I am not even close to a java expert. In fact, I haven't written a line of Java since I was forced to in a CS class in college back in 2000. But I looked through the awt functions and a lot of them having rendering sub functions and it is possible some initializer or something is trying to interact with X somehow. This wouldn't be a problem in windows because the gui interface is always there to interact with in windows.
 
Old 02-11-2004, 07:46 PM   #7
Cand1e
LQ Newbie
 
Registered: Feb 2004
Location: Location, Location.
Distribution: Debian / XP
Posts: 6

Original Poster
Rep: Reputation: 0
I can (sort of) understand why Sun would make X system calls for the awt stuff, however I don't really understand why they are trying to use X to draw on a BufferedImage!

Java is a great programmnig language! cross platform, unified structure, OO, simple (all things are relative... prolog...!), it has loads of in-built classes - from Strings to windows.
 
Old 02-11-2004, 08:30 PM   #8
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Well, again, I could easily be talking out of my pinky toe or something here.... but is there no way to manipulate an image file with something that isn't a member of the Abstract Windows Toolkit? I mean, if all you want to do is write images to a file it seams kind of silly to have all that class structure for a graphical interface included. There must be some file IO commands outside of the scope of AWT.
 
Old 02-12-2004, 03:04 AM   #9
Cand1e
LQ Newbie
 
Registered: Feb 2004
Location: Location, Location.
Distribution: Debian / XP
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by jtshaw There must be some file IO commands outside of the scope of AWT.
Quote:
Originally posted by Cand1e is there a way round it?
Quote:
Originally posted by Cand1e how can I resolve this issue
I've been reading the API and *I* havn't found anything yet, but I'll keep searching and this was part of my search, asking here.

there are FILE IO commands out of the scope, i.e. I can read files and write files, I can probably read and write image files, but the problem is image manipulation, getting hold of a Graphics[2D] object so I can call Graphics.draw(Shape s)); before writing the image back to file.

Last edited by Cand1e; 02-12-2004 at 03:12 AM.
 
Old 02-13-2004, 01:27 AM   #10
hiteshmaisheri
Member
 
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231

Rep: Reputation: 30
from the knowledge i know about java it is difficult to manipulate files as such....
 
Old 02-15-2004, 11:44 AM   #11
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
You can use XVFB (the X Virtual Framebuffer) to use AWT on headless *NIX boxen... it is installed with X on most distros. This is the code I use to start XVFB on my server for an on-the-fly thumbnail application:

#!/bin/sh

# Shell script to startup the Xvfb server

echo "Starting Xvfb services..."
Xvfb :1 -fp /usr/X11R6/lib/X11/fonts/misc/,/usr/X11R6/lib/X11/fonts/75dpi/ -screen 0 1x1x24 &
echo "Done."

This starts a 1x1 virtual X screen (you can write off the edges of the screen so you might as well take up as little memory as possible imho) at 24 bpp. Then when you start your java application, you have to run it like this:

export DISPLAY=localhost:1.0
java org.bunk.my.Application

and it will run AWT functions in the virtual X server.

HTH

B.

Last edited by german; 02-15-2004 at 11:50 AM.
 
Old 02-15-2004, 11:58 AM   #12
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
I just thought, you could also either use JDK1.4 which has headless AWT support built-in (I believe you just pass something like java -Djava.awt.headless=1), or you could try PJA (http://www.eteks.com/pja/en/) which is a third party library for headless AWT operations.

From my experience with headless AWT, my first post is the easiest to implement, and stays true to standard java libraries. I haven't played with the 1.4 headless options.
 
Old 02-18-2004, 07:18 AM   #13
worldmagic
Member
 
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
Setting "-Djava.awt.headless=true" will throw the execption "HeadlessException" if you try to create an instance of a awt class.. Im having the same problem right now, how to create offscreen images..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA: Graphics problem z24561 Programming 1 10-28-2005 10:37 PM
graphics with java simcox1 Mandriva 3 04-02-2005 11:55 AM
Thttpd for graphics server SupaDucta Linux - Software 3 11-15-2004 05:51 PM
using postfix to send through a relay server that requires authentication surban99 Linux - Software 1 04-27-2004 06:16 PM
Java Graphics in Linux hiteshmaisheri Linux - Software 10 02-08-2004 10:39 AM


All times are GMT -5. The time now is 04:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration