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

NoSuchElementException will be generated about JEditorPane

    XMLWordPrintable

Details

    • 1.2.2
    • sparc
    • solaris_2.6
    • Verified

    Description

      JDK: 1.2.2-D
      OS: Solaris 2.6 & 2.7
      Locale: zh_CN

      In jsk1.2.2-D, NoSuchElementException will be generated about JEditorPane.

      Following is a program to reproduce it.

      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.border.*;
      import javax.swing.text.*;

      import java.awt.*;
      import java.util.*;
      import java.awt.event.*;
      import java.net.URL;
      import java.net.MalformedURLException;
      import java.io.*;


      public class JEditorPaneTester extends JPanel implements HyperlinkListener {
          JEditorPane html;
          
          public static void main(String args[]) {
      JFrame f = new JFrame("Html View Tester");
      f.getContentPane().setLayout(new BorderLayout());
      f.getContentPane().add(new JEditorPaneTester(), BorderLayout.CENTER);
      f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      });
      //f.pack();
      f.setSize(400, 400);
      f.show();
          }

          public JEditorPaneTester() {
      setLayout(new BorderLayout());
      SoftBevelBorder loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
      EmptyBorder emptyBorder10 = new EmptyBorder(10, 10, 10, 10);
      setBorder(new CompoundBorder(loweredBorder, emptyBorder10));
      setAlignmentY(TOP_ALIGNMENT);

      try {
      URL url = null;
      String urlName = "file:" +
      System.getProperty("user.dir") + File.separator +
      "html" + File.separator + "example_zh_CN" +
      ".html";
      //"html" + File.separator + "example_" +
      //Locale.getDefault().toString() + ".html";
      try {
      url = new URL(urlName);
      } catch (java.net.MalformedURLException ex) {
      System.err.println("Attempted to open a bad URL: " + url);
      url = null;
      }

      if (url != null) {
      html = new JEditorPane(url);
      html.setEditable(false);
      html.addHyperlinkListener(this);
      JScrollPane scroller = new JScrollPane();
      JViewport vp = scroller.getViewport();
      vp.add(html);
      vp.setBackingStoreEnabled(true);
      add("Center", scroller);
      }
      } catch (MalformedURLException e) {
      System.out.println("Malformed URL: " + e);
      } catch (IOException e) {
      System.out.println("IOException: " + e);
      }
          }


          public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      linkActivated(e.getURL());
      }
          }

          protected void linkActivated(URL u) {
      Cursor c = html.getCursor();
      Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
      html.setCursor(waitCursor);
      SwingUtilities.invokeLater(new PageLoader(u, c));
          }

          class PageLoader implements Runnable {

      PageLoader(URL u, Cursor c) {
      url = u;
      cursor = c;
      }

      public void run() {
      if (url == null) {
      html.setCursor(cursor);
      Container parent = html.getParent();
      parent.repaint();
      } else {
      Document doc = html.getDocument();
      try {
      html.setPage(url);
      } catch (IOException ioe) {
      html.setDocument(doc);
      getToolkit().beep();
      } finally {
      url = null;
      SwingUtilities.invokeLater(this);
      }
      }
      }

      URL url;
      Cursor cursor;
          }
      }
      ==============================================================================

      save this file and html.tar to a directory
      tar xvf html.tar in the same directory
      java JEditorPaneTester
      Exception will generate:

      java.util.NoSuchElementException
              at java.util.Vector.lastElement(Vector.java, Compiled Code)
              at javax.swing.text.html.StyleSheet$CssParser.parse(StyleSheet.java, Compiled Code)
              at javax.swing.text.html.StyleSheet.addRule(StyleSheet.java, Compiled Code)
              at javax.swing.text.html.HTMLDocument$HTMLReader.addCSSRules(HTMLDocument.java, Compiled Code)
              at javax.swing.text.html.HTMLDocument$HTMLReader$HeadAction.end(HTMLDocument.java, Compiled Code)
              at javax.swing.text.html.HTMLDocument$HTMLReader.handleEndTag(HTMLDocument.java, Compiled Code)
              at javax.swing.text.html.parser.DocumentParser.handleEndTag(DocumentParser.java, Compiled Code)
              at javax.swing.text.html.parser.Parser.parse(Parser.java, Compiled Code)
              at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java, Compiled Code)
              at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java, Compiled Code)
              at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java, Compiled Code)
              at javax.swing.JEditorPane.read(JEditorPane.java, Compiled Code)
              at javax.swing.JEditorPane.read(JEditorPane.java, Compiled Code)
              at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java, Compiled Code)













      jim.hu@prc 1999-01-25

      Attachments

        Activity

          People

            svioletsunw Scott Violet (Inactive)
            jhusunw Jim Hu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: