简体   繁体   中英

How do I prevent a headless exception in Java?

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM