aSyncTask crashing on Nexus S but not Droid 1
I have an aSyncTask used for a loading screen. In my doBackground, I开发者_开发技巧 have
mCampusMap = (CampusMap) findViewById(R.id.CampusMap);
mCampusMap.setVisibility(View.VISIBLE);
to fire up my openGL View which takes 5 seconds or so to load.
Everything works fine on the Droid, but on a Nexus S i get the following error:
10-05 17:56:02.906: ERROR/AndroidRuntime(876): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
If you define the AsyncTask class inside your Activity class, try this:
runOnUiThread(new Runnable() {
public void run() {
((CampusMap) findViewById(R.id.CampusMap)).setVisibility(View.VISIBLE);
}
});
精彩评论