我绝对是暴风雨的初学者。这是风暴入门(书)的一个例子。 wordcounter例子。我在本地使用风暴,当我使用maven运行此示例时,我收到此错误。 Maven命令使用:
[knk@kinock Storm-Starter]$mvn exec:java -Dexec.mainClass="TopologyMain" -Dexec.args="src/main/resources/words.txt"
java.lang.NullPointerException: null
at spouts.WordReader.open(WordReader.java:62) ~[classes/:na]
at backtype.storm.daemon.executor$fn__3430$fn__3445.invoke(executor.clj:504) ~[storm-core-0.9.0.1.jar:na]
at backtype.storm.util$async_loop$fn__444.invoke(util.clj:401) ~[storm-core-0.9.0.1.jar:na]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.4.0.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
5608 [Thread-22-word-reader] ERROR backtype.storm.daemon.executor -
java.lang.NullPointerException: null
at spouts.WordReader.open(WordReader.java:62) ~[classes/:na]
at backtype.storm.daemon.executor$fn__3430$fn__3445.invoke(executor.clj:504) ~ [storm-core-0.9.0.1.jar:na]
at backtype.storm.util$async_loop$fn__444.invoke(util.clj:401) ~[storm-core- 0.9.0.1.jar:na]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.4.0.jar:na]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
5610 [Thread-6] INFO backtype.storm.daemon.executor - Loading executor __system:[-1 -1]
5618 [Thread-6] INFO backtype.storm.daemon.task - Emitting: __system __system ["startup"]
5619 [Thread-6] INFO backtype.storm.daemon.executor - Loaded executor tasks __system: [-1 -1]
5624 [Thread-6] INFO backtype.storm.daemon.executor - Finished loading executor __system:[-1 -1]
5629 [Thread-24-__system] INFO backtype.storm.daemon.executor - Preparing bolt __system:(-1)
5638 [Thread-24-__system] INFO backtype.storm.daemon.executor - Prepared bolt __system:(-1)
5668 [Thread-6] INFO backtype.storm.daemon.executor - Loading executor __acker:[1 1]
5670 [Thread-6] INFO backtype.storm.daemon.task - Emitting: __acker __system ["startup"]
5671 [Thread-6] INFO backtype.storm.daemon.executor - Loaded executor tasks __acker:[1 1]
5672 [Thread-22-word-reader] INFO backtype.storm.util - Halting process: ("Worker died")
5678 [Thread-6] INFO backtype.storm.daemon.executor - Timeouts disabled for executor __acker:[1 1]
5679 [Thread-6] INFO backtype.storm.daemon.executor - Finished loading executor __acker: [1 1]
这是代码提升异常的阻止。第62行标有注释。
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
try {
//this.collector = collector;
this.context = context;
this.fileReader = new FileReader(conf.get("wordsFile").toString());//exception is raised here. 62nd line
} catch (FileNotFoundException e){
throw new RuntimeException("Error reading file ["+conf.get("wordFile")+"]");
}
this.collector = collector;
}
提前致谢..
答案 0 :(得分:1)
[knk @ kinock Storm-Starter] $ mvn exec:java -Dexec.mainClass =“TopologyMain”-Dexec.args =“src / main / resources / words.txt”
在上面的命令中,应该给出文件的完整路径,否则java无法找到路径。
答案 1 :(得分:0)
最可能的原因可能是它无法从wordsFile
对象中读取Config
条目...例如,如果您有一些像FileReader(conf.get("wordsFile").toString());
然后如果你使用conf.put("SomeOtherWordsFile", ..)
,那么它将尝试通过spout's
对象找到文件路径位置(在conf
open方法内)搜索实际不存在的密钥wordsFile