问题
I have an Applet and when I try to run it on my laptop, a headless exception is thrown by Java at the line where a JFrame is created. Now I know why the JFrame normally causes the exception but my computer was not in headless mode to begin with. I'm also still not sure what headless mode entails exactly.
I'm running Ubuntu and have a pretty recent version of java.
Also, I have successfully created JFrames and such in Eclipse when running Windows on my laptop (if that helps).
回答1:
Have you tried setting java.awt.headless=true
? I have done this once before on Solaris with no x-server in order to use the java.awt print libraries. It worked a treat. However it was more than five years ago and I don't have the source handy.
See Setting java.awt.headless=true programmatically
PS Are you on Ubuntu server or desktop? If the latter, I'd question why Java thinks you are headless.
回答2:
Look @ following link that might help:
http://www.theserverside.com/discussions/thread.tss?thread_id=52535
来源:https://stackoverflow.com/questions/11403190/how-do-i-prevent-a-headless-exception-in-java