Нужно изменить текст в JTextArea
при изменении текста в определенных (других) полях. Вызов метода, который вызывает метод изменения текста, проходит гладко, но само изменение текста вылетает с NPE. Я так понял, у меня не объявлен сам JTextArea
. Но проблема в том, что он объявлен и прекрасно отрисовывается.
Как исправить эту ошибку?
FormatterMain.java:
private JTextArea FormattedTextView;
public static void main(String[]args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
...
FormatterEngine formatterEngine = new FormatterEngine();
...
JTextArea FormattedTextView = new JTextArea();
FormattedTextView.setBorder(new MatteBorder(5, 5, 5, 5, (Color) SystemColor.textHighlight));
JScrollPane scrollPane = new JScrollPane(FormattedTextView);
frame.getContentPane().add(scrollPane, BorderLayout.NORTH);
FormattedTextView.setFont(textFont);
FormattedTextView.setEnabled(false);
FormattedTextView.setRows(10);
...
}
});
}
public void setTextInMainArea(String text) {
this.FormattedTextView.setText(text);
}
....
FormatterEngine.java:
...
FormatterMain formatterMain = new FormatterMain();
...
public void refreshFinishedTextView(boolean Free) {
...
formatterMain.setTextInMainArea("test"); //ошибка
...
}
run
) переменнойFormattedTextView
я вижу. Объявление глобальной переменной (поля)FormattedTextView
я не вижу.private JTextArea FormattedTextView
вFormattedTextView
находитсяnull
.private JTextArea formattedTextView=new JTextArea();
А из run уберите. И еще, название переменных, объектов пишется с маленькой буквы.