首页 > 移动平台 > 详细

Android - Bug: runOnUiThread

时间:2015-01-13 08:57:23      阅读:851      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!