gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:18:34 27 4
gpt4 key购买 nike

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

此外,我还可以从同一项目中的普通类中读取所有值。

错误

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 指向的本地文件在您的所有服务器中均不可用,那么您就会遇到问题。另外,请检查文件的格式。

关于java.util.Properties$LineReader.readLine 处的 java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31516727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com