android - Error when executing an asynchTask -
i have viewpager
actiontabs
each action tab has own layout. in 1 of layouts have button when clicked asynctask
changes background color should executed shown below.
at run time receive below errors logcat.
please have @ logcat errors , kindly let me know missing in code.
code
class asynccolor extends asynctask<string, integer, string> { @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); } @override protected string doinbackground(string... params) { // todo auto-generated method stub (int = 0; < params.length; i++){ rl_3.setbackgroundcolor(color.parsecolor(params[i])); } return "done"; } @override protected void onprogressupdate(integer... values) { // todo auto-generated method stub super.onprogressupdate(values); } @override protected void onpostexecute(string result) { // todo auto-generated method stub super.onpostexecute(result); btn_asynch.settext(result); } } @override public void onresume() { // todo auto-generated method stub super.onresume(); btn_asynch.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub new asynchcolor().execute(asynchblue, asynchgreen, asynchred, asynchblue1, asynchgreen1, asynchred1); } });
logcat:
12-06 13:13:15.049: e/androidruntime(5591): fatal exception: asynctask #1 12-06 13:13:15.049: e/androidruntime(5591): java.lang.runtimeexception: error occured while executing doinbackground() 12-06 13:13:15.049: e/androidruntime(5591): @ android.os.asynctask$3.done(asynctask.java:300) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.futuretask.setexception(futuretask.java:222) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.futuretask.run(futuretask.java:242) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 12-06 13:13:15.049: e/androidruntime(5591): @ java.lang.thread.run(thread.java:841) 12-06 13:13:15.049: e/androidruntime(5591): caused by: android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.viewrootimpl.checkthread(viewrootimpl.java:6832) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.viewrootimpl.invalidatechildinparent(viewrootimpl.java:1053) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.viewgroup.invalidatechild(viewgroup.java:4518) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.view.invalidate(view.java:11687) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.view.setbackgrounddrawable(view.java:16248) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.view.setbackground(view.java:16139) 12-06 13:13:15.049: e/androidruntime(5591): @ android.view.view.setbackgroundcolor(view.java:16101) 12-06 13:13:15.049: e/androidruntime(5591): @ com.example.viewpagerwithactiontabstest00.aufgabe_7$asynchcolor.doinbackground(aufgabe_7.java:72) 12-06 13:13:15.049: e/androidruntime(5591): @ com.example.viewpagerwithactiontabstest00.aufgabe_7$asynchcolor.doinbackground(aufgabe_7.java:1) 12-06 13:13:15.049: e/androidruntime(5591): @ android.os.asynctask$2.call(asynctask.java:288) 12-06 13:13:15.049: e/androidruntime(5591): @ java.util.concurrent.futuretask.run(futuretask.java:237)
you cant touch ui thread elements in doinbackground
@override protected string doinbackground(string... params) { // todo auto-generated method stub (int = 0; < params.length; i++){ publishprogress(params[i]); } return "done"; } @override protected void onprogressupdate(integer... values) { // todo auto-generated method stub super.onprogressupdate(values); rl_3.setbackgroundcolor(color.parsecolor(values[i])); }
Comments
Post a Comment