1. 程式人生 > >You cannot start a load on a not yet attached View or a Fragment ...

You cannot start a load on a not yet attached View or a Fragment ...

專案app出現標題上的錯誤,定位到程式碼中的這句:

Glide.with(getContext()).load(hairdresserDetail.getHead_photo())
                    .into((CircleImageView) newsHeader.findViewById(R.id.head_photo));

Glide載入圖片報錯?百度下,還真有類似的情況,詳解請看如下連結

https://blog.csdn.net/loners_/article/details/73521968

看了上面博主的文章分析,可能是activity被銷燬,而getContext()傳入了空值導致的。加上以下判斷

if(getContext()!=null){
            Glide.with(getContext()).load(hairdresserDetail.getHead_photo())
                    .into((CircleImageView) newsHeader.findViewById(R.id.head_photo));
        }

再測未復現標題所示的錯誤。