Java Log4j PropertyConfigurator.configure()将不接受eclipse中的字符串

Java Log4j PropertyConfigurator.configure()将不接受eclipse中的字符串,java,logging,log4j,Java,Logging,Log4j,我有一个奇怪的问题,可能是一些简单的问题,但我已经在谷歌上搜索了20分钟,没有任何解决方案 我试图在Eclipse中使用log4j。我下载了最新的zip并添加到我的类路径中。我通过从教程中复制创建了属性文件。属性文件位于我的项目的根文件夹中,名为“log4j.properties”。该文件包含 #define the console appender log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender # now

我有一个奇怪的问题,可能是一些简单的问题,但我已经在谷歌上搜索了20分钟,没有任何解决方案

我试图在Eclipse中使用log4j。我下载了最新的zip并添加到我的类路径中。我通过从教程中复制创建了属性文件。属性文件位于我的项目的根文件夹中,名为“log4j.properties”。该文件包含

#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender

# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

# now map our console appender as a root logger, means all log messages will go to this     appender
log4j.rootLogger = DEBUG, consoleAppender
我的类如下所示,eclipse在PropertyConfigurator.configure()行有以下错误。 这条线上有多个标记 -令牌“log4j.properties”上出现语法错误,请删除此令牌 -令牌上的语法错误,构造位置错误

然而,log4j的api显示PropertyConfiguration应该接受字符串。有什么建议吗? -

package org.dnsdojo.ryanhost.GA.MuPlusOne;
导入java.util.Random;
导入org.apache.log4j.Logger;
导入org.apache.log4j.propertyConfiguration;
公共类基因组
{
私有静态记录器=Logger.getLogger(Genome.class);
PropertyConfigurator.configure(“log4j.properties”);
字节[]基因组;
随机rng=新随机();
字符串genomeString=“”;
公共基因组(int-stringLength,int-motorSet)
{
genome=新字节[stringLength*7*motorSet];//stringLength取决于您希望拥有的字节数。对于arpibot,这取决于读取的传感器读数的数量
for(int i=0;i
您当前有
属性配置程序。请在类块中配置
,以便编译器进行投诉。将语句(以及其他非声明性语句)移动到方法或
静态
初始值设定项块中。

您不能在类中的任何位置执行任意代码!你需要把你的方法调用放在一个
静态{}
块、一个
{}
块或某个方法中。哇,多棒的一个derp>>在我的辩护中,我想我已经看这个太久了!谢谢,一个问题由此产生——一旦我修复了代码,我的记录器就会返回一些奇怪的行号。它跳过了一些,复制了另一些。这是因为我的属性文件还是我的代码?很难说。检查部署的代码是否与当前代码一致,即未使用旧类版本运行。不确定您使用了多少个记录器。退房…谢谢,我会就此提出另一个问题。我尝试添加log4j.additivity.consoleAppender=false,但没有change@Reimeus我很抱歉,但我是对的:(
package org.dnsdojo.ryanhost.GA.MuPlusOne;

import java.util.Random;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class Genome
{
private static Logger logger = Logger.getLogger(Genome.class);
PropertyConfigurator.configure("log4j.properties");
byte[] genome;
Random rng = new Random();
String genomeString = "";

public Genome ( int stringLength, int motorSet )
{
    genome = new byte[ stringLength * 7 * motorSet]; // stringLength depends on how many bytes you wish to have. For the arpibot this is dependant on the number of sensor readings taken
    for (int i = 0; i < genome.length; i++)
    {
        genome[i] = (byte)rng.nextInt(2);
        genomeString += genome[i];
    }
    logger.debug(genomeString);     
}

public byte[] getGenome()
{
    return genome;
}

public byte[] mutate (float mutationStep)
{
    return genome;                                  //placeholder
}

}