What could be the reason for this exception? I dont know what causes this. It appears at different situations. It seams pretty random. The program is still running without any limitations.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.PlainView.paint(Unknown Source)
at javax.swing.text.FieldView.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Only this class uses AWT.
public class GraphicalUserInterface {
private int currentLineNumber = 0;
private Font font;
private JFrame frame = new JFrame("Database");
private Image icon;
private JTextField input = new JTextField();
private JTextPane output = new JTextPane();
private JPanel panel = new JPanel();
private int pressedKey = 0;
private JScrollPane scrollPane = new JScrollPane(panel);
private StyledDocument styledDocument = output.getStyledDocument();
private Object synchronizerInputConfirm = new Object();
private Object synchronizerKeyInput = new Object();
private Object synchronizerKeyPressed = new Object();
private JTextField time = new JTextField();
private Timer timer = new Timer();
public GraphicalUserInterface() throws FontFormatException, IOException, InterruptedException {
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
ClassLoader classLoader = this.getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("DejaVuSansMono.ttf");
font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
font = font.deriveFont(Font.PLAIN, 15);
inputStream.close();
icon = new ImageIcon(classLoader.getResource("icon.png")).getImage();
ActionListener inputListener = new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
synchronized (synchronizerInputConfirm) {
synchronizerInputConfirm.notify();
}
}
};
KeyListener keyListener = new KeyListener() {
@Override public void keyPressed(KeyEvent e) {
pressedKey = e.getExtendedKeyCode();
if (pressedKey == 8) {
input.replaceSelection("");
}
else if (pressedKey == 10) {
synchronized (synchronizerKeyInput) {
synchronizerKeyInput.notify();
}
}
synchronized (synchronizerKeyPressed) {
synchronizerKeyPressed.notify();
}
}
@Override public void keyReleased(KeyEvent e) {}
@Override public void keyTyped(KeyEvent e) {}
};
DocumentListener documentListener = new DocumentListener() {
@Override public void changedUpdate(DocumentEvent e) {}
@Override public void insertUpdate(DocumentEvent e) {
synchronized (synchronizerKeyInput) {
synchronizerKeyInput.notify();
}
}
@Override public void removeUpdate(DocumentEvent e) {}
};
input.getDocument().addDocumentListener(documentListener);
panel.setLayout(new BorderLayout(0, 0));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setIconImage(icon);
frame.setResizable(false);
time.setEditable(false);
time.setEnabled(false);
time.setFont(font);
time.setBorder(null);
time.setBackground(Color.BLACK);
time.setDisabledTextColor(Color.WHITE);
panel.add(time, BorderLayout.NORTH);
output.setEditable(false);
output.setEnabled(false);
output.setFont(font);
output.setBorder(null);
output.setBackground(Color.BLACK);
output.setDisabledTextColor(Color.WHITE);
panel.add(output, BorderLayout.CENTER);
input.setBorder(null);
input.setFont(font.deriveFont(Font.ITALIC));
input.setCaretColor(Color.WHITE);
input.setBackground(Color.BLACK);
input.setForeground(Color.WHITE);
input.addActionListener(inputListener);
input.addKeyListener(keyListener);
input.setSelectedTextColor(Color.BLACK);
input.setSelectionColor(Color.WHITE);
output.add(input, BorderLayout.AFTER_LAST_LINE);
timer.scheduleAtFixedRate(new UpdateTime(time), 0, 500);
scrollPane.setViewportBorder(null);
scrollPane.setBorder(null);
JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
verticalScrollBar.setPreferredSize(new Dimension(0, 0));
verticalScrollBar.setUnitIncrement(10);
JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
horizontalScrollBar.setPreferredSize(new Dimension(0, 0));
horizontalScrollBar.setUnitIncrement(10);
frame.setContentPane(scrollPane);
panel.add(output);
for (StringFormat format : StringFormat.values()) {
format.initialise(styledDocument);
}
frame.setSize(800, 530);
input.setSize(770, input.getFontMetrics(font).getHeight());
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
}
Aucun commentaire:
Enregistrer un commentaire