Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4869484

Toolkit.createImage and getImage work incorrectly in headless mode.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 5.0
    • client-libs
    • None
    • 2d
    • sparc
    • solaris_9

      The methods of class java.awt.Toolkit
      public abstract Image createImage
      public abstract Image getImage
      work incorrectly in headless mode under jdk 1.5.0

      getImage method returns null for valid image in this case, createImage throws
      NullPointerException.

      Here is example:
      import java.awt.*;

      public class test02 {
          public static void main (String[] args) {
              Image im = Toolkit.getDefaultToolkit().getImage("im.gif");
              if (im == null) {
                  System.out.println("Failed: im == null");
              }
              Toolkit.getDefaultToolkit().createImage("im.gif");
              System.out.println("OKAY");
              System.exit(0);
          }
      }


      --- Output: ---
      % java -version
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b07)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b07, mixed mode)
      % java test02
      OKAY
      % java -Djava.awt.headless=true test02
      Failed: im == null
      Exception in thread "main" java.lang.NullPointerException
              at sun.awt.motif.MToolkit.createImage(MToolkit.java:395)
              at sun.awt.SunToolkit.createImage(SunToolkit.java:498)
              at sun.awt.HeadlessToolkit.createImage(HeadlessToolkit.java:333)
              at test02.main(test02.java:9)
      ------------

            campbell Christopher Campbell (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: