android - Cannot change UI in runOnUiThread -


i want change textview content result of calculation in thread, crashing when execution. here's code.

new thread(new runnable() {         public void run() {             while (i < 5) {                i++;             }             getactivity().runonuithread(new runnable() {                 public void run() {                     textview txv = (textview) getview().findviewbyid(r.id.txvone);                     log.d("123","i = "+ i);                     txv.settext(i);//crash!!!                 }             });         } }).start(); 

enter image description here

you need pass string type settext() method. when pass integer type, performs lookup r(see : r) file string resource specified id. since id not match item in strings.xml file, exception thrown resourcenotfoundexception.

like sree said, try code below, guaranteed work.

txv.settext(string.valueof(i))); 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -