開発環境はmaven, spring, java7, Androidアプリではないです。
JUNITでTESTしましたが、JSONのレスポンスが返ってきませんでした。
twitter4j.properties
oauth.consumerKey=略
oauth.consumerSecret=略
oauth.accessToken=略
oauth.accessTokenSecret=略
TwitterService.java
@Autowired
private Twitter twitter;
/**
* Tweetを検索する
* @param keywords
* @return
* @throws Exception
*/
public Set<Status> getTweet(String slice, Integer limit, String keywords) throws Exception {
Set<Status> results = new HashSet<Status>();
Query query = new Query(keywords);
query.setLang("ja");
// ループ回数
if (limit > 1500) limit = 1500;
int roupe = limit / 200;
int limited = limit % 200;
Long finalId = null;
for (int i = 0; i <= roupe; i++) {
query.setCount(i == roupe ? limited : 200);
if (finalId != null) query.setMaxId(finalId);
QueryResult result = twitter.search(query);
finalId = result.getSinceId();
results.addAll(result.getTweets());
}
return results;
}
下記の行でNullPoが発生します。
QueryResult result = twitter.search(query);
以下、スタックトレースです。
java.lang.NullPointerException at twitter4j.QueryResultJSONImpl.(QueryResultJSONImpl.java:43) at twitter4j.JSONImplFactory.createQueryResult(JSONImplFactory.java:145) at twitter4j.TwitterImpl.search(TwitterImpl.java:255) at jp.dip.略.getTweet(TwitterService.java:62) at jp.dip.melonslv.TwitterWrappHelperTest.testツイート取得(TwitterTest.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
大したことはしていないはずなんですがなぜ動かないのでしょうか。
twitter4jご存じの方いらっしゃいましたら教えてください。