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

NullPointerException raised when making call getFontMetrics w/JDK1.1.1 on Sparc

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5.1, windows_95

      Description

      When running the following code, select File/Print from the menu bar.
      Then click "Print" in the print dialog. I then get a run-time error,
      a NullPointerException. The call trace shows it to be 5 levels below
      the call in my program which generates the exception.

      Exception occurred during event dispatching:
      java.lang.NullPointerException
      at java.util.Hashtable.get(Hashtable.java)
      at sun.awt.motif.X11FontMetrics.getFontMetrics(X11FontMetrics.java:186)
      at sun.awt.motif.MToolkit.getFontMetrics(MToolkit.java:208)
      at sun.awt.motif.PSGraphics.getFontMetrics(PSGraphics.java:136)
      at java.awt.Graphics.getFontMetrics(Graphics.java:195)
      at DrawingArea.paint(DrawingArea.java:12)
      at java.awt.Component.print(Component.java:1160)
      at dareout.actionPerformed(dareout.java:43)
      at java.awt.MenuItem.processActionEvent(MenuItem.java:336)
      at java.awt.MenuItem.processEvent(MenuItem.java:307)
      at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:144)
      at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:136)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:65)


      2 test source files: dareout.java & DrawingArea.java


      // dareout.java
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.io.*;


      public final class dareout extends Frame implements ActionListener {

         private DrawingArea draw_here;

      public void makeMenuItem (Menu menu, String name) {
         MenuItem mi;
         mi = new MenuItem (name);
         mi.addActionListener (this);
         menu.add (mi);
      }

      public dareout (String ftitle) {
         super(ftitle);
         MenuBar menubar;
         Menu file, actions, display;
         file = new Menu ("File");
         makeMenuItem (file, "Print");
         makeMenuItem (file, "Exit");
         menubar = new MenuBar ();
         setMenuBar (menubar);
         menubar.add (file);
         draw_here = new DrawingArea ();
         add (draw_here);
         setBackground (Color.white);
         pack ();
         setSize (new Dimension (1026, 749));
      }

      public void actionPerformed (ActionEvent e) {
         if (e.getSource() instanceof MenuItem)
            if (e.getActionCommand().equals("Print")) {
               PrintJob pj = getToolkit().getPrintJob (this,
                  "Printing Test", (Properties)null);
               if (pj != null) {
                  Graphics pg = pj.getGraphics();
                  if (pg != null) {
                     draw_here.print (pg);
                     pg.dispose ();
                  }
                  pj.end();
               }
            }
            else if (e.getActionCommand().equals("Exit"))
               System.exit (0);
      }
      public static void main (String[] args) {
         dareout f;
         f = new dareout ("dareout");
         f.show ();
      }
      }

      // DrawingArea.java
      public final class DrawingArea extends Canvas {
         float left = 0f, right = 1016f, top = 0f, bottom = 688f;

      public void paint (Graphics g) {
         int stringwidth, stringheight;
         stringheight = (g.getFontMetrics()).getHeight();
         stringwidth = (g.getFontMetrics()).stringWidth("SAMPLE TITLE")/2;
      }

      }

        Attachments

          Activity

            People

            Assignee:
            ehawkessunw Eric Hawkes (Inactive)
            Reporter:
            jbenoit Jonathan Benoit (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: