Android app will only display one JSON element -


here picture of screen outputi'm making app class retrieve stock information api. have set way retrieve json data based on user's input stock symbol. there 2 textviews right now, 1 shows company name , 1 shows stock change value. however, textview has text set first displayed, other 1 unaffected. here console output when search button clicked:

04-24 23:24:29.782 8144-8589/com.webdesigners.stockmarket w/system.err: android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.viewrootimpl.checkthread(viewrootimpl.java:6357) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.viewrootimpl.invalidatechildinparent(viewrootimpl.java:909) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.viewgroup.invalidatechild(viewgroup.java:4690) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.view.invalidateinternal(view.java:11801) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.view.invalidate(view.java:11765) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.view.view.invalidate(view.java:11749) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.widget.textview.checkforrelayout(textview.java:6850) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.widget.textview.settext(textview.java:4057) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.widget.textview.settext(textview.java:3915) 04-24 23:24:29.783 8144-8589/com.webdesigners.stockmarket w/system.err: @ android.widget.textview.settext(textview.java:3890) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ com.webdesigners.stockmarket.mainactivity$1$1.onresponse(mainactivity.java:74) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ okhttp3.realcall$asynccall.execute(realcall.java:133) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ okhttp3.internal.namedrunnable.run(namedrunnable.java:32) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 04-24 23:24:29.784 8144-8589/com.webdesigners.stockmarket w/system.err: @ java.lang.thread.run(thread.java:818)

        searchbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             string usersymbol = searchedittext.gettext().tostring();              try             {                 okhttpclient client = new okhttpclient();                 request request = new request.builder().url("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22" + usersymbol + "%22%29&env=store://datatables.org/alltableswithkeys&format=json").build();                 client.newcall(request).enqueue(new callback() {                     @override                     public void onfailure(call call, ioexception e) {                         e.printstacktrace();                     }                      @override                     public void onresponse(call call, final response response) throws ioexception {                         if (!response.issuccessful())                         {                          }                         else                         {                             string responsedata = response.body().string();                             try                             {                                 textview symbol = (textview)findviewbyid(r.id.symbol);                                 textview change = (textview)findviewbyid(r.id.change);                                  //get object @ "quote" level attributes                                 jsonobject jsonobject = new jsonobject(responsedata);                                 jsonobject query = jsonobject.getjsonobject("query");                                 jsonobject results = query.getjsonobject("results");                                 jsonobject quote = results.getjsonobject("quote");                                  long changevalue = quote.getlong("change");                                 string changestring = long.tostring(changevalue);                                 assert change != null;                                 change.settext(changestring);                                  assert symbol != null;                                 string companyname = quote.getstring("name");                                 string companynameconcat = "name: " + companyname;                                 symbol.settext(companynameconcat);                              }                             catch(exception e)                             {                                 e.printstacktrace();                             }                         }                     }                 });             }             catch(exception e)             {              }         }     }); 

your callbacks executed not on main thread. reason errors see. call runonuithread when need update ui.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -