How do I prevent a headless exception in Java?

我只是一个虾纸丫 提交于 2019-12-23 12:00:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!