gpt4 book ai didi

android - java.lang.IllegalStateException : You cannot call Glide. registerComponents() 中的 get(),改用提供的 Glide 实例 -- Glide Version 4.9.0

转载 作者:太空狗 更新时间:2023-10-29 14:35:48 29 4
gpt4 key购买 nike

从 Gilde 3.7.0 迁移到 Glide 4.9.0。

如下定义我的 MyAppGlideModule。

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
private static final int IMAGE_DISK_CACHE_MAX_SIZE = 250 * 1024 * 1024;

@Override
public void applyOptions(@NonNull final Context context, @NonNull GlideBuilder builder) {
super.applyOptions(context, builder);
builder.setDiskCache(new DiskLruCacheFactory(
FileUtils.getCacheFile(context, false).getAbsolutePath() + File.separator + GLIDE_CACHE_PATH,
IMAGE_DISK_CACHE_MAX_SIZE));
// builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
}

@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
// super.registerComponents(context, glide, registry);
OkHttpClient client = new OkHttpClient();
client.newBuilder().connectTimeout(15, TimeUnit.SECONDS)
.addNetworkInterceptor(new TSImageRetryIntercepter(3))
.readTimeout(15, TimeUnit.SECONDS);
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
registry.replace(GlideUrl.class, InputStream.class, factory);
}

@Override
public boolean isManifestParsingEnabled() {
return false;
}
}

当我运行如下加载图像的代码时

Glide.with(mContext)
.load(imageBean.getGlideUrl())
.override(with, height)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.dontAnimate()
.placeholder(R.drawable.shape_default_image)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.shape_default_image)
.into(view);

出现以下错误。

Process: com.my.package.debug, PID: 5561
java.lang.IllegalStateException: You cannot call Glide.get() in registerComponents(), use the provided Glide instance instead
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:180)
at com.bumptech.glide.Glide.get(Glide.java:168)
at com.bumptech.glide.Glide.getRetriever(Glide.java:689)
at com.bumptech.glide.Glide.with(Glide.java:716)
at com.my.package.list.adapter.DynamicListItemForShorVideo.initVideoView(DynamicListItemForShorVideo.java:106)
at com.my.package.list.adapter.DynamicListItemForShorVideo.convert(DynamicListItemForShorVideo.java:77)
at com.my.package.list.adapter.DynamicListItemForShorVideo.convert(DynamicListItemForShorVideo.java:45)
at com.my.package.recyclerview.base.ItemViewDelegateManager.convert(ItemViewDelegateManager.java:93)
at com.my.package.recyclerview.MultiItemTypeAdapter.convert(MultiItemTypeAdapter.java:55)
at com.my.package.recyclerview.MultiItemTypeAdapter.onBindViewHolder(MultiItemTypeAdapter.java:99)
at com.my.package.recyclerview.MultiItemTypeAdapter.onBindViewHolder(MultiItemTypeAdapter.java:17)
at com.my.package.recyclerview.wrapper.HeaderAndFooterWrapper.onBindViewHolder(HeaderAndFooterWrapper.java:76)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at com.my.package.layout.SmartRefreshLayout.onLayout(SmartRefreshLayout.java:623)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1775)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)

最佳答案

当你使用 GlideAppModule 时,从文档中,你应该使用:

GlideApp.with(mContext)

代替:

Glide.with(mContext)

关于android - java.lang.IllegalStateException : You cannot call Glide. registerComponents() 中的 get(),改用提供的 Glide 实例 -- Glide Version 4.9.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56273689/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com