码迷,mamicode.com
首页 > 移动开发 > 详细

Android - Bug: runOnUiThread

时间:2015-01-13 08:58:41      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:mystra   android   runonuithread   getactivity   bug   

Bug: runOnUiThread


本文地址: http://blog.csdn.net/caroline_wendy


Bug:
java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)‘ on a null object reference
     at me.chunyu.ChunyuDoctor.Modules.DoctorService.h.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:818)

原因:

I‘m almost sure that this is caused when the thread finish its work but the activity is no longer visible.
You should check if the "getActivity()" call return null, and ...

getActivity()有可能为空,需要提前判断;
位置:DocServiceBannerFragment;
                if (getActivity() == null)
                    return;

                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        _updateBanners(bannerItems, bannerImages);
                    }
                });

即可,完成。

Android - Bug: runOnUiThread

标签:mystra   android   runonuithread   getactivity   bug   

原文地址:http://blog.csdn.net/caroline_wendy/article/details/42671855

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!