开发者

aSyncTask crashing on Nexus S but not Droid 1

开发者 https://www.devze.com 2023-04-11 15:02 出处:网络
I have an aSyncTask used for a loading screen. In my doBackground, I开发者_开发技巧have mCampusMap = (CampusMap) findViewById(R.id.CampusMap);

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);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号