Java虚拟机崩溃

时间:2010-05-25 13:53:41

标签: java jvm crash

我正在使用SCO OpenServer 5.0.7操作系统。 我的JVM是版本1.4,我也有1.5

当我在GUI文本字段中尝试输入范围0x80 - 0x9f中的字符时,我的JVM将CPU加载到100%,并且阻止它的唯一方法是终止jvm进程。

当我在java控制台应用程序中输入相同范围的字符时,一切都很好。

我猜测jvm如何实现控制台stdin和GUI键事件的差异。

有人有想法,我该如何解决这个问题?

我不相信,这是一个程序流程。这是一个标准化的例子:

// TextForm.java

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;

import java.awt.Insets;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;
import java.awt.Container;

import java.awt.event.*;

public class TextForm extends JPanel {

   private final JTextField[] tf;

   // Create a form with the given labels, tooltips, and sizes
   public TextForm (String[] labels, String[] tips, int[] widths) {
      tf = new JTextField[labels.length];

      setLayout (new GridBagLayout());
      final GridBagConstraints gbc = new GridBagConstraints();
      gbc.anchor = GridBagConstraints.WEST;
      gbc.insets = new Insets (3,3,3,3);

      // Add labels and fields as specified
      for (int i=0; i<labels.length; i++) {
         final JLabel l = new JLabel (labels[i]);

         // Create an accessibility-friendly field
         tf[i] = new JTextField (widths[i]);
         tf[i].setToolTipText (tips[i]); // sets accessible desc too!
         l.setLabelFor (tf[i]);          // sets accessibleName for tf[i]!

         // lay out label & field
         gbc.gridy = i;
         gbc.gridx = 0;
         add(l, gbc);
         gbc.gridx = 1;
         add(tf[i], gbc);
    }
  }

   // Get the contents of one of the TFs.
   public String getEnteredText(int index) {
      return tf[index].getText();
   }

   // A simple example program
   public static void main(String[] args) {
      final String[] labels = { "First Name", "Middle Initial", "Last Name", "Age" };
      final String[] descs = { "First Name","Middle Initial", "Last Name", "Age" };

      final int[] widths = { 15, 1, 15, 3 };

      final TextForm form = new TextForm(labels, descs, widths);

      // A button that dumps the field contents
      final JButton dump = new JButton("Dump");
      class DumpListener implements ActionListener {
         public void actionPerformed(ActionEvent ev) {
            System.out.println(form.getEnteredText(0));
            System.out.println(form.getEnteredText(1));
            System.out.println(form.getEnteredText(2));
            System.out.println(form.getEnteredText(3));
         }
      }
      dump.addActionListener (new DumpListener());

      final JFrame f = new JFrame("Text Form");
   //   frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // Requires Java 1.3
      final Container c = f.getContentPane();
      c.setLayout (new BorderLayout());
      c.add(form, BorderLayout.CENTER);
      c.add(dump, BorderLayout.SOUTH);
      f.pack();
      f.setVisible(true);
  }
}

问题是,jvm在关键事件发生时崩溃了,所以我无法在我的程序中调试它。

1 个答案:

答案 0 :(得分:1)

两个环境之间在默认Charset方面可能存在差异。我注意到NetBeans,Eclipse和许多控制台可以设置为平台默认之外的其他东西。检查是不会有害的:

System.out.println(System.getProperty("file.encoding"));
System.out.println(Charset.defaultCharset().name());