[slf4j-user] Logger in subclass in NULL

Chris Pratt thechrispratt at gmail.com
Thu Jun 6 18:17:08 CEST 2013


Loggers should be static.
  (*Chris*)


On Thu, Jun 6, 2013 at 8:17 AM, Ulrich <Forums at gombers.de> wrote:

> When calling override-method in a subclass from the constructor of the
> superclass the LOGGER in the subclass is not initialized; the program
> fails with
> NullPointerException.
> E.g:
> Subclass is:
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class TestLoggerSubClass extends TestLoggerSuperClass {
>
>         private final Logger LOGGER =
> LoggerFactory.getLogger(this.getClass());
>         public TestLoggerSubClass() {
>                 super("TestLoggerSubClass");
>         }
>
>         @Override
>         public void display() {
>                 int summe = 15+5;
>                 LOGGER.info("Summe={}",summe);
>         }
> }
>
>
> Superclass is:
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class TestLoggerSuperClass {
>
>         private final Logger LOGGER =
> LoggerFactory.getLogger(this.getClass());
>         public TestLoggerSuperClass(String name) {
>                 LOGGER.info("wurde mit Namen {} gerufen", name);
>                 display();
>         }
>
>         public void display() {
>                 int summe = 5+5;
>                 LOGGER.info("Summe={}",summe);
>         }
> }
>
> The program fails, as already said, with NullPointerException in the
> LOGGER-Statement of the Override-Method in the subclass.
>
> Can I anything do to have the LOGGER initialized before invoking the
> constructor
> of the superclass?
>
> Thanks in advance,
> Ulrich
> _______________________________________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20130606/71a45fae/attachment.html>


More information about the slf4j-user mailing list