gpt4 book ai didi

java - ORA-29532 : Java call terminated by uncaught Java exception: java. awt.HeadlessException

转载 作者:行者123 更新时间:2023-11-30 12:07:03 28 4
gpt4 key购买 nike

我使用以下代码执行 java 类来截取我的屏幕:

import java.awt.AWTException;
import java.awt.FlowLayout;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class FullScreenCapture extends JFrame {
private static final long serialVersionUID = 1L;

public static String capture() {
FullScreenCapture f = new FullScreenCapture();
String Ret;
try {
Thread.sleep(5000);
System.setProperty("java.awt.headless", "true");
Robot robot = new Robot();
String fileName = "D://FullScreenshot.jpg";

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit()
.getScreenSize());
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println("Headless mode: " + ge.isHeadless());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, "jpg", new File(fileName));
Ret ="Capture Saved Successfully";
} catch (Exception e) {
System.out.println("Exception occurred");
Ret ="Wrong Error";
}
return Ret;
}

}

程序在netbeans或者cmd中执行都没有问题,但是当把java类的java加载到oracle数据库中时将其作为函数调用,返回错误消息 java.awt.HeadlessException

enter image description here enter image description here

最佳答案

您正在使用 java.awt.Robot这需要一个图形化的、非 headless 的环境才能工作。根据 Robot() javadoc :

AWTException - if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true

Oracle 数据库服务器不提供图形环境,因此无法运行您的代码。根据 User Interfaces on the Server Oracle 文档:

Oracle Database furnishes all core Java class libraries on the server, including those associated with presentation of the user interfaces. However, it is inappropriate for code running on the server to attempt to materialize or display a user interface on the server. Users running applications in Oracle JVM environment should not be expected nor allowed to interact with or depend on the display and input hardware of the server where Oracle Database is running.

关于java - ORA-29532 : Java call terminated by uncaught Java exception: java. awt.HeadlessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55206564/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com