java.lang.NullPointerException 在 java.util.Properties$LineReader.readLine

java.lang.NullPointerException at java.util.Properties$LineReader.readLine

我是 运行 Apache storm 拓扑,我正在尝试从属性文件中读取值。我的主要功能能够在螺栓抛出以下错误时读取值。

此外,我能够从同一个项目中的正常 class 中读取所有值。

错误

java.lang.NullPointerException at 
java.util.Properties$LineReader.readLine(Properties.java:434) at 
java.util.Properties.load0(Properties.java:353) at 
java.util.Properties.load(Properties.java:341) at 
com.StormConsumer.commons.FilePropertyManager.loadPrope
rtyFile(FilePropertyManager.java:54) at 
com.StormConsumer.commons.FilePropertyManager.getProper
ty(FilePropertyManager.java:34) at 
com.StormConsumer.bolt.SessionIdCounter.prepare(SessionIdCounter.java:42) at 
backtype.storm.topology.BasicBoltExecutor.prepare(BasicBoltExecutor.java:43) 
at backtype.storm.daemon.executor$fn__4722$fn__4734.invoke(executor.clj:692) 
at backtype.storm.util$async_loop$fn__458.invoke(util.clj:461) at 
clojure.lang.AFn.run(AFn.java:24) at java.lang.Thread.run(Thread.java:745) 

如何解决?

这是class:

public class SessionIdCounter extends BaseBasicBolt {

private static final long serialVersionUID = 1L;

Cluster cluster;
Session session;

/*private static final String KEYSPACE = FilePropertyManager.getProperty(
        ApplicationConstants.CASSANDRA_CONSTANTS_FILE,
        ApplicationConstants.KEYSPACE);
private static final String CREATE_TABLE = FilePropertyManager.getProperty(
        ApplicationConstants.CASSANDRA_QUERY_FILE,
        ApplicationConstants.TABLE_SessionID);*/

/**
 * creates a table SessionID with fields sessionid, year, month, day, hour,
 * dayofyear, weekofyear, count.
 */

public void cleanup() {

}

public void prepare(Map stormConf, TopologyContext context) {
    final String KEYSPACE = FilePropertyManager.getProperty(
            ApplicationConstants.CASSANDRA_CONSTANTS_FILE,
            ApplicationConstants.KEYSPACE);
    final String CREATE_TABLE = FilePropertyManager.getProperty(
            ApplicationConstants.CASSANDRA_QUERY_FILE,
            ApplicationConstants.TABLE_SessionID);

    cluster = CassandraConnection.setupCassandraClient();
    session = CassandraConnection.getSessionWithRetry(cluster, KEYSPACE);

    session.executeAsync(CREATE_TABLE);
}

public void declareOutputFields(OutputFieldsDeclarer declarer) {
}

public void execute(Tuple input, BasicOutputCollector collector) {

    String sessionid = input.getString(0);
    int year = input.getInteger(1);
    int month = input.getInteger(2);
    int day = input.getInteger(3);
    int hour = input.getInteger(4);
    int dayofyear = input.getInteger(5);
    int weekofyear = input.getInteger(6);

    /*
     * Inserting Values In Cassandra
     */

    String insertUpdateTable = "UPDATE SessionID SET count = count + 1 "
            + "where sessionid = \'" + sessionid + "\' AND year = " + year
            + " AND month = " + month + " AND day = " + day
            + " AND hour = " + hour + " AND dayofyear = " + dayofyear
            + " AND weekofyear = " + weekofyear + " ;";
    session.executeAsync(insertUpdateTable);

}

}

问题出在您的 属性 文件中。如果 ApplicationConstants.CASSANDRA_CONSTANTS_FILE 指向的本地文件在您的所有服务器中都不可用,那么您就有问题了。另外,请检查您的文件格式。