I have the following problem:
I have app. which I want to log information to JTextArea
with Log4J. I know that I must create a class which extends AppenderSkeleton
and to make a logic to log message and append it to the text area component when it click on run button. This is the class I made:
public class TextAreaAppender extends AppenderSkeleton
{
public static JTextArea logTextArea = new JTextArea();
@Override
public void append(LoggingEvent logEvent)
{
String logMessage = this.layout.format(logEvent);
logTextArea.append(logMessage);
}
@Override
public void close()
{
}
@Override
public boolean requiresLayout()
{
return false;
}
}
In the class the UI and logic for buttons there is the following code for the text area component:
logTextArea = new JTextArea();
logTextArea.setEnabled(false);
scrollTextArea = new JScrollPane(logTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollTextArea.setBounds(50, 300, 300, 140);
TextAreaAppender.logTextArea = logTextArea;
Here is my config in log4j properties file:
log4j.rootLogger = INFO, textarea
log4j.appender.textarea = bis.debug.mode.ui.TextAreaAppender
log4j.appender.textarea.layout = org.apache.log4j.PatternLayout
log4j.appender.textarea.layout.ConversionPattern= %d{HH:mm:ss} -%m%n
And now when I click the run button it must log the errors which are happened to the text area component but it throws an Exception :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException..
Which means that no log message is appended and I do not know why it happens. Can you please tell me how?