- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在处理一个小组项目,代码可以在我队友的 PC 上运行,但我一直遇到特定于 MacOS 的错误。而这一次我似乎被卡住了(没有简单的谷歌搜索答案)。
在a previous post我发现我需要“-Djava.awt.headless=true
”作为 VM 设置才能正确运行我的模拟。现在,当我尝试在某些 JFrame 中生成时,由于该 VM 标志,它们都遇到了可爱的“java.awt.HeadlessException
”异常。
我也希望能够在我的 MacBook 上生成这些 JFrame。
我需要 -Djava.awt.headless
同时为真和假,我的程序才能在 Mac 上正常运行。如果我正确地理解了我的问题,那意味着我手上有一个大问题。
编辑:在我的 Macbook 上的虚拟机中运行它使我能够正确运行该项目。这远非理想的解决方案。我仍在寻找解决这个晦涩问题的方法。
-Djava.awt.headless
。最佳答案
解决此问题的最佳方法可能是返回并以不同的方式解决您原来的问题。
您必须确保您没有在主线程(GLFW 线程)中初始化您的BufferedImage
,它必须单独完成。很难从您最初的问题中分辨出来,但这看起来像是那里的部分原因。启动一个新线程来进行图像处理。
请参阅此答案底部的我的解决方案和建议以获取快速摘要,还可以在此处查看其他有相同问题的人:Java Creating Instance of BufferedImage Freezes Program
关于为什么您的代码在 Windows 而不是 Mac 上运行的快速说明:这是因为这两个操作系统通常运行不同的 openGL 实现,并且通常 Mac 可能会落后并错过一堆可能解决问题的更新/更改,例如这样它就不会在 openGL 线程上初始化 BufferedImage
时卡住。
如果以上方法不起作用,那么让我们先看看什么是 headless 模式。 (强调我的):
See link at bottom for full article and more info.
Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking. Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data.
Where it is applicable? Let's say that your application repeatedly generates a certain image, for example, a graphical authorization code that must be changed every time a user logs in to the system. When creating an image, your application needs neither the display nor the keyboard. Let's assume now that you have a mainframe or dedicated server on your project that has no display device, keyboard, or mouse. The ideal decision is to use this environment's substantial computing power for the visual as well as the nonvisual features. An image that was generated in the headless mode system then can be passed to the headful system for further rendering.
那么什么时候应该使用 headless 模式:
On a machine that has no display device, keyboard, or mouse.
那不是你吗?但是,如果那是你(LWJGL?),那么让我们看看如何使用 headless 模式:
An image that was generated in the headless mode system then can be passed to the headful system for further rendering.
这意味着您应该有一段特殊的 headless 代码来处理 headless 图像,然后将图像传回带头的普通 JFrame。
那么为什么它对你来说失败了:
Many components are affected if a display device, keyboard, or mouse is not supported. An appropriate class constructor throws a HeadlessException
- Button
- Checkbox
- Choice
- Dialog
- FileDialog
- Frame
- Label
- List
- Menu
- MenuBar
- MenuItem
- PopupMenu
- Scrollbar
- ScrollPane
- TextArea
- TextField
- Window
some classes, such as Canvas or Panel, can be executed in headless mode.
完美,所以我们只需要注意 headless 模式下使用的内容。您询问如何既可以使用也可以不使用 headless 模式,而不是使用 VM 选项全局设置 headless 模式 -Djava.awt.headless
you can do it programmatically within your code在需要的地方使用 System.setProperty("java.awt.headless", "true");
。 JFrame
应该是正常的(不是 headless 的),但您可以毫无问题地生成一个 headless 的 JPanel
。
您创建一个正常的有头主线程,没有生成 JFrames 的 VM 选项,然后使用该主线程生成一个新的子线程并将该线程中的 LWJGL 位设置为 headless ,这样您就可以运行您的 LWJGL代码没有问题,同时您仍然可以从主线程获得 JFrames。请记住确保缓冲图像未在主 LWJGL/OpenGL 线程中完成。
headless 信息来源: http://www.oracle.com/technetwork/articles/javase/headless-136834.html
关于java - 制作 JFrame 时抛出 LWJGL java.awt.HeadlessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47006058/
AWT-EventQueue 线程和 AWT-Shutdown 线程没有在我们的应用程序中关闭。有没有一种调试技术可以找出它们不存在的原因?有什么特别的东西要寻找吗? 最佳答案 如果你的意思是关闭所有
java.awt.* 和 java.awt.event.* 有什么区别? 最佳答案 这只是两个不同的包。 当您说import java.awt.*时,它仅导入那些完全属于java.awt包的类,而不是
我正在将 aadhar 集成到 liferay 中。我尝试了这个链接 https://developer.uidai.gov.in/site/book/export/html/18 所以我想将其集成到
我想知道如何确定 Java.awt.Rectangle 是否包含特定 Java.awt.Color 的像素。我一直在到处寻找,但找不到任何关于此的信息,甚至找不到任何可能的信息。 所以我想知道如何确定
我试图在组件和图像之间切换面板的内容,它适用于组件: imgpanel.removeAll(); Component comp; if ((comp = player.getVisualCompone
我在使用 JAVA 编码时遇到一些错误,我一直在尝试解决这个问题,也试图找到其他有同样问题的人并修复它,但没有任何效果... 嗯..这是代码 package ca.vanzeben.game;
我想我可以尝试一下 JAXB 来处理存储和恢复设置。但即使是“最简单”的例子我也遇到了麻烦: import java.awt.Point; public class Config { public
这个问题已经有答案了: Import package.* vs import package.SpecificType [duplicate] (10 个回答) 已关闭 7 年前。 在我现在正在进行的
private static byte[] get_byte_data(BufferedImage image) { //WritableRaster raster = image.get
是否有可能获得标准 AWT Cursor以位图图像的形式(例如 BufferedImage )或任何可在 Graphics2D 上绘制的图像?例如,文本光标 new Cursor(Cursor.TEX
我的代码中有三个点,我想填充它们之间的区域,或者换句话说,在 3 个点之间绘制并填充一个三角形。 我想过简单地用 for 循环绘制线条(从 x1 到 x2),但我认为这不会有效,是否有其他更有效的方法
我正在制作一个小脚本,我使用鼠标键来节省我的工作时间。我可以正确、良好地使用鼠标键。但是,当使用 java.awt.Robot 和 java.awt.event.KeyEvent 时,鼠标键基本上被忽
我正在尝试在 scala 中使用 java awt 来制作一个简单的桌面应用程序。我已经在它上面工作了几天,没有任何问题,直到我有 2 天没有碰它,当我回来时,我得到一个 java.lang.NoCl
我在 VisualVM 和线程 View 中监视一个 JavaFX 程序,不断有 AWT-EventQueue-0 和 AWT-Shutdown 线程被创建和销毁。这是正常行为吗?这是什么原因? 最佳
我需要将 java.awt.geom.Area 或 java.awt.Shape 转换为 java.awt.Polygon。我所知道的是:isSingular = true、isPolygonal =
我正在重新使用 Java 并审查我的一些旧代码,并且我看到了很多我已经完成的地方 import javax.swing.*; import java.awt.*; 或者实际上从 swing/awt 包
晚上, 我在玩一个小的 swing 应用程序,我添加了一个按钮来响应按下。因此我需要实现 ActionListener。我已经添加了这一行: import java.awt.*; 但它告诉我找不到“A
我有这个 java 代码: Editor() { javax.swing.SwingUtilities.invokeLater(new Runnable() { pub
请帮我解决这个问题 sun.awt.image.ToolkitImage 无法转换为 java.awt.image.BufferedImage if (shape.hasImage())
嗨 Stackoverflow 的 friend 们 我最近将 Jenkins 服务器配置到 Apache Tomcat 7.0.42我制作的程序是将 jenkins.war 文件部署到 tomcat
我是一名优秀的程序员,十分优秀!