2014-09-10 55 views
0

我此行我的代码错误PMD:有关记录

private transient final Logger logger = LoggerFactory.getLogger(getClass()); 

我建我的项目和PMD检查却对我说:

The Logger variable declaration does not contain the static and final modifiers. 

我能做些什么来解决这个问题?我试图把static修饰符,但与此错误出现:

Cannot make a static reference to the non-static method getClass() from the type Object 

回答

2

如果您在主Makefile使用它,它的静态

,我现在会用记录仪这样

private static final Logger LOG = Logger.getLogger(Main.class.getSimpleName()); 
+0

工作, 谢谢! – KTF 2014-09-10 20:19:31

+0

实际上,它应该是'私有静态最终记录器LOG = ...'。您不希望任何人为记录器引用分配新值。 – 2014-09-11 17:11:34

+0

哦,谢谢,我一直在学习java可能2个月现在是啊,我不是很好 – Emrage 2014-09-11 18:21:30