fa__
fa__

Reputation: 327

Twitter4j FilterQuery NullPointerException when location is not provided

I am building an application to extract tweets including different filters that may or not be used in every case (location, language, track). I employ a FilterQuery and several TwitterStreamingListener. Basically I build a query including every listener requirements and then I collect the tweets from twitter stream.

twitterStream.filter(query);

It works fine except in the case when none of the listeners includes location requirements. Then, location field is not used and remains null:

FilterQuery{count=0, follow=null, track=[party,night,house], locations=[null], language=[en]}

There are no problems when other fields remain null but in this case, I get this error:

Exception in thread "Twitter Stream consumer-18[Establishing connection]" java.lang.NullPointerException
ERROR [stderr] (Twitter Stream consumer-18[Establishing connection])    at twitter4j.FilterQuery.toLocationsString(FilterQuery.java:200)
ERROR [stderr] (Twitter Stream consumer-18[Establishing connection])    at twitter4j.FilterQuery.asHttpParameterArray(FilterQuery.java:182)
ERROR [stderr] (Twitter Stream consumer-18[Establishing connection])    at twitter4j.TwitterStreamImpl.getFilterStream(TwitterStreamImpl.java:306)
ERROR [stderr] (Twitter Stream consumer-18[Establishing connection])    at twitter4j.TwitterStreamImpl$7.getStream(TwitterStreamImpl.java:287)
ERROR [stderr] (Twitter Stream consumer-18[Establishing connection])    at twitter4j.TwitterStreamImpl$TwitterStreamConsumer.run(TwitterStreamImpl.java:488)

Should I always include location information in my FilterQuery? Or is there any other expression to be employed (instead of null)that means no location is required?

Upvotes: 0

Views: 124

Answers (1)

fa__
fa__

Reputation: 327

The correct syntax for this query would be:

FilterQuery{count=0, follow=null, track=[party,night,house], locations=null, language=[en]}

And that is the query formed when there are no calls to the query.locations() method. However, my code was calling this method sending an empty list of locations, which resulted in a different query that was not accepted by the API.

Upvotes: 0

Related Questions