java.util.Properties $ LineReader.readLine中的java.lang.NullPointerException

时间:2015-07-20 12:37:42

标签: java properties nullpointerexception apache-storm

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

此外,我能够读取同一项目中普通类的所有值。

错误

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) 

如何解决?

这是班级:

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);

}

}

1 个答案:

答案 0 :(得分:1)

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