java - 如何在 twitter 的 Maven 中运行代码

标签 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>

最佳答案

README.md 中写道: 您需要使用您自己的凭据填写 twitter4j.properties 文件。 Java 应用程序找不到该文件并返回 NPE。
(in 为 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());
  }

关于java - 如何在 twitter 的 Maven 中运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23247429/

相关文章:

java - Java中的线程何时从内存中删除?

spring - 从命令行运行 Spring Batch 作业

maven - Spark 中的 java.lang.NoSuchMethodError

python-2.7 - 使用 Python Tweepy 搜索术语交集和并集

f# - 使用 Windows Azure 和 F# 进行 Twitter Streaming API 记录和处理

java - JavaFX运行时主要方法

java - 在 appengine 端点 json 中保留数值

java - 使用 RequestBuilder 表单发布

java - Spring 4 : Java 8 compatibility

facebook - 不使用 Twitter 的 API 嵌入推文是否违法?