java - Sending Request Using A Separate Thread -


i'm trying send api request yelp android application. got sample code send request in java here https://github.com/yelp/yelp-api/tree/master/v2/java

it worked when ran script provided in repository, however, when added code android application, got error.

here's android app code:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      yelpapi yelp = new yelpapi(             getstring(r.string.yelp_consumer_key),             getstring(r.string.yelp_consumer_secret),             getstring(r.string.yelp_token),             getstring(r.string.yelp_token_secret));      string result = yelp.searchforbusinessesbylocation("bar", "san jose, ca");     system.out.println(result); } 

and stack trace:

--------- beginning of crash 07-23 12:50:23.848    e/androidruntime﹕ fatal exception: main     process: pid: 2328     java.lang.runtimeexception: unable start activity componentinfo{.mainactivity}: org.scribe.exceptions.oauthconnectionexception: there problem while creating connection remote service.             @ android.app.activitythread.performlaunchactivity(activitythread.java:2298)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2360)             @ android.app.activitythread.access$800(activitythread.java:144)                           ... 

i found similar problems on internet, , figured because couldn't send request using main thread. how send request using separate thread?

if want create new thread, can this:

 new thread(new runnable() {     public void run() {         yelpapi yelp = new yelpapi(         getstring(r.string.yelp_consumer_key),         getstring(r.string.yelp_consumer_secret),         getstring(r.string.yelp_token),         getstring(r.string.yelp_token_secret));          string result = yelp.searchforbusinessesbylocation("bar", "san jose, ca");         system.out.println(result);     }  }).start(); 

information on android threads can found at: http://developer.android.com/guide/components/processes-and-threads.html


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -