如何防止Java中出现无头异常? [英] How do I prevent a headless exception in Java?

查看:107
本文介绍了如何防止Java中出现无头异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Applet,当我尝试在笔记本电脑上运行Applet时,Java在创建JFrame的行抛出了无头异常.现在,我知道了为什么JFrame通常会导致异常,但是我的计算机开始时没有处于无头模式.我也仍然不确定到底需要哪种无头模式.

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.

我正在运行Ubuntu,并且具有Java的最新版本.

I'm running Ubuntu and have a pretty recent version of java.

此外,在便携式计算机上运行Windows时,我已经在Eclipse中成功创建了JFrames等.

Also, I have successfully created JFrames and such in Eclipse when running Windows on my laptop (if that helps).

推荐答案

您是否尝试设置java.awt.headless=true?我以前在没有x服务器的Solaris上执行过一次此操作,以便使用java.awt打印库.它奏效了.但是,距今已有五年多了,我手头上也没有资料.

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.

请参见以编程方式设置java.awt.headless = true

PS您是在Ubuntu服务器还是台式机上?如果是后者,我会问为什么Java认为您没有头脑.

PS Are you on Ubuntu server or desktop? If the latter, I'd question why Java thinks you are headless.

这篇关于如何防止Java中出现无头异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆