Android - Bug: runOnUiThread

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

即可,完成。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。