java - Multiple queries in different methods Twitter4j Processing -


i trying execute separate queries in different methods, code below not actual code example of error, have

twitter twitter = new twitterfactory(cb.build()).getinstance();

called in both methods, error

illegalstateexception: cannot use builder longer, build() has been called

if make global same error, me being stupid cant work out, iv been staring @ long now.

here code:

configurationbuilder cb = new configurationbuilder();    double lat = 51.5171;   double lon = 0.1062;   double res = 37;   string resunit = "mi";  public void setup(){  cb.setoauthconsumerkey("xxxxxxxxxxxxxxxxxxxxxx"); cb.setoauthconsumersecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); cb.setoauthaccesstoken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); cb.setoauthaccesstokensecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");    querylon();   querybir(); }  void querylon(){ try { twitter twitter = new twitterfactory(cb.build()).getinstance();    (int j = 0; j < 5; j++) {    query query = new query();   query.setrpp(100);    queryresult result = twitter.search(new query().geocode(new geolocation(lat,lon), res, resunit));   arraylist tweets = (arraylist) result.gettweets();     (int = 0; < tweets.size(); i++) {    tweet t = (tweet) tweets.get(i); //user u= twitter.showuser("twitter");  string location = t.getlocation(); println("location: " + location);    } } }  catch (twitterexception te) { println("couldn't connect: " + te); };  }  void querybir(){ try {  twitter twitter = new twitterfactory(cb.build()).getinstance();    (int j = 0; j < 5; j++) {    query query = new query();   query.setrpp(100);    queryresult result = twitter.search(new query().geocode(new geolocation(lat,lon), res, resunit));   arraylist tweets = (arraylist) result.gettweets();     (int = 0; < tweets.size(); i++) {    tweet t = (tweet) tweets.get(i);  string location = t.getlocation(); println("location: " + location);      } } }  catch (twitterexception te) { println("couldn't connect: " + te); };  } 

any appreciated, cheers.

forgot mention im using twitter4j , processing

looks pretty clear: error tells build() can called once, , you're trying call multiple times. so, simple solution: when want make new twitterfactory, either capture result of cb.build() in variable first time call it, , reuse that, or create new instance of configurationbuilder , call build() everty time create new twitterfactory, although seems pretty wasteful. try capture cb.build() first.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -