我正在尝试使用 twitter4j API 来使用 twitter 的流 API。在我添加了几个轴 2 库之前,它工作得很好。
代码:
BlockingQueue<String> queue = twitter.getBlockingQueue();
//Infinite loop to always receive the messages
while (true) {
String twitterServerReply = null;
try{
twitterServerReply = queue.take();
}
catch(Exception e){
e.printStackTrace();
}}
以下是我得到的例外:
Exception in thread "hosebird-client-io-thread-0" java.lang.NullPointerException
at com.twitter.hbc.httpclient.RestartableHttpClient.getConnectionManager(RestartableHttpClient.java:83)
at com.twitter.hbc.httpclient.ClientBase.run(ClientBase.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
这是我的 POM.XML:
<?xml version="1.0"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.twitter</groupId>
<artifactId>hbc-example</artifactId>
<version>2.2.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Hosebird Client Examples</name>
<dependencies>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>hbc-core</artifactId> <!-- or hbc-twitter4j -->
<version>2.2.0</version> <!-- or whatever the latest version is -->
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
我必须使用 AXIS 2,因为我需要使用一些 SOAP 网络服务。任何人都可以帮忙检查我是否可能遇到问题?
注意:如果我删除所有轴 2 依赖项,它工作得很好。