Java Virtual Machine crashes
Im using SCO OpenServer 5.0.7 operating system. My JVM is version 1.4 and also I have 1.5
When I'm trying to input a character in range 0x80 - 0x9f in GUI Text field, my JVM loads the CPU up to 100%, and the only way to stop It is to kill the jvm process.
When I input character in same range in java console application, It is all fine.
I'm guessing there is a diffrence how jvm interpetating console stdin and GUI key events.
Does anybody have an idea, how can I fix this problem?
I dont beleave, It is a program flow. Here is a standart example which crashes:
// 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 开发者_如何学PythongetEnteredText(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);
}
}
The problem is that, jvm crashes at the moment the key event is made, so I cannot debugg it from within my program.
There might be a disparity between the two environments with regard to the default Charset
. I've noticed that NetBeans, Eclipse and many consoles can be set to something other than the platform default. It couldn't hurt to check:
System.out.println(System.getProperty("file.encoding"));
System.out.println(Charset.defaultCharset().name());
精彩评论