如何在maven中为twitter运行代码

时间:2014-04-23 14:29:38

标签: java maven twitter twitter4j

我最近在网上发现了一个非常有用的代码,用于Twitter推文分析并讲述即将发生的事件。

https://github.com/mvogiatzis/first-stories-twitter#implementation-summary

我尝试按照“如何运行”一节中的说明运行此代码,但我在命令行中收到错误,如附图所示。任何人都可以请它为什么会来。??

[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ First-Story-Detection >>
>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ First-Story-Detection <<
<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ First-Story-Detection --
-
[WARNING]
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:744)
Caused by: 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 crawler.Crawler.main(Crawler.java:100)
        ... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.421 s
[INFO] Finished at: 2014-04-23T17:04:44+05:00
[INFO] Final Memory: 11M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (d
efault-cli) on project First-Story-Detection: An exception occured while executi
ng the Java class. null: InvocationTargetException: NullPointerException -> [Hel
p 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception
E:\Course\FYP\Working\After mid defense\Twitter Service\first-stories-twitter-ma
ster\first-stories-twitter-master>

1 个答案:

答案 0 :(得分:1)

在README.md中写道: 您需要使用自己的凭据填写twitter4j.properties文件。 Java应用程序找不到该文件,并返回NPE。
(在null中,prop.load(in)生成一个NPE!)
Crawler.java:

  try {
      InputStream in = Crawler.class.getClassLoader()
              .getResourceAsStream("twitter4j.properties");
      prop.load(in);
  } catch (IOException e) {
      log.error(e.toString());
  }