android - Is there any problem with this code? -



android - Is there any problem with this code? -

it produce stopped unexpectedly problem when force search button.

public class beautiful extends activity { imageview radar; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); this.requestwindowfeature(window.feature_no_title); this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.beautiful); radar = (imageview) findviewbyid(r.id.radar); button search = (button) findviewbyid(r.id.magnifier); imageview text = (imageview) findviewbyid(r.id.text); mediaplayer siren = mediaplayer.create(this, r.raw.siren); search.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub thread counter = new thread(new runnable(){ @override public void run() { // todo auto-generated method stub try{ thread.sleep(2000); radar.setimageresource(r.drawable.radar_new_full); thread.sleep(3000); radar.setimageresource(r.drawable.radar_new_50); thread.sleep(2000); radar.setimageresource(r.drawable.radar_new_found); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } finally{ } } }); counter.start(); } }); }

here logcat warnings:

07-07 17:36:17.298: warn/dalvikvm(274): threadid=15: thread exiting uncaught exception (group=0x4001b188) 07-07 17:36:17.306: error/androidruntime(274): uncaught handler: thread thread-8 exiting due uncaught exception 07-07 17:36:17.306: error/androidruntime(274): android.view.viewroot$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 07-07 17:36:17.306: error/androidruntime(274): @ android.view.viewroot.checkthread(viewroot.java:2683) 07-07 17:36:17.306: error/androidruntime(274): @ android.view.viewroot.requestlayout(viewroot.java:557) 07-07 17:36:17.306: error/androidruntime(274): @ android.view.view.requestlayout(view.java:7918) 07-07 17:36:17.306: error/androidruntime(274): @ android.view.view.requestlayout(view.java:7918) 07-07 17:36:17.306: error/androidruntime(274): @ android.view.view.requestlayout(view.java:7918) 07-07 17:36:17.306: error/androidruntime(274): @ android.view.view.requestlayout(view.java:7918) 07-07 17:36:17.306: error/androidruntime(274): @ android.widget.imageview.setimageresource(imageview.java:271) 07-07 17:36:17.306: error/androidruntime(274): @ example.beautiful$1$1.run(beautiful.java:46) 07-07 17:36:17.306: error/androidruntime(274): @ java.lang.thread.run(thread.java:1096)

read anr dialog link , how update ui other thread painless threading

android

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -