Vote count:
0
i have a viewpagwe with some actiontabs each action tab has its own layout. in one of the layouts i have a button that when clicked an AsynchTask that changes the background color should be executed as shown below.
At run time I receive the below errors from the logcat.
please have a look at the logcat errors and kindly let me know what i am missing in the code.
COde class AsynchColor extends AsyncTask {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
for (int i = 0; i < 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: An error occured while executing doInBackground()
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.os.AsyncTask$3.done(AsyncTask.java:300)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.lang.Thread.run(Thread.java:841)
12-06 13:13:15.049: E/AndroidRuntime(5591): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6832)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1053)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.ViewGroup.invalidateChild(ViewGroup.java:4518)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.View.invalidate(View.java:11687)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.View.setBackgroundDrawable(View.java:16248)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.View.setBackground(View.java:16139)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.view.View.setBackgroundColor(View.java:16101)
12-06 13:13:15.049: E/AndroidRuntime(5591): at com.example.viewpagerwithactiontabstest00.Aufgabe_7$AsynchColor.doInBackground(Aufgabe_7.java:72)
12-06 13:13:15.049: E/AndroidRuntime(5591): at com.example.viewpagerwithactiontabstest00.Aufgabe_7$AsynchColor.doInBackground(Aufgabe_7.java:1)
12-06 13:13:15.049: E/AndroidRuntime(5591): at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-06 13:13:15.049: E/AndroidRuntime(5591): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
asked 20 secs ago
Error when executing an asynchTask
Aucun commentaire:
Enregistrer un commentaire