Possible Duplicate:
Android : CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views
Now I am working on an application.I want to show a progressbar until i get a true reply from called method.I used the following code.
progressBar = new ProgressDialog(this);
progressBar.setCancelable(true);
progressBar.setMessage("Loading");
progressBar.show();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
final boolean flag= GetFixtureDetailsJsonFunction();
if (flag==true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();
protected boolean GetFixtureDetailsJsonFunction()
{
//some code
return true;
}
But I am getting the exception
03-14 15:48:23.722: E/AndroidRuntime(910): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Please help me friends
your problem is that one of your thread is trying to access the data that belongs to another thread, you cannot do that because that can lead to serious data corruption.
follow the following article for solution to the problem.
https://web.archive.org/web/20200810154212/http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html