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

问题: i execute java class to screenshot of my screen with following code: import java.awt.AWTException; import java.awt.FlowLayout; import java.awt.GraphicsEnvironment; import...

问题:

i execute java class to screenshot of my screen with following code:

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;
   }

}

the program don't have any problems when executed in netbeans or in cmd, but when load java of java class into oracle database to call it as function,return error message java.awt.HeadlessException

enter image description here enter image description here


回答1:

You are using java.awt.Robot which needs a graphical, non-headless environment to work. As per Robot() javadoc:

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

The Oracle database server doesn't provide a graphical environment so it can't run your code. As per User Interfaces on the Server Oracle docs:

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.

  • 发表于 2019-03-19 01:50
  • 阅读 ( 269 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除