gpt4 book ai didi

android - java.lang.IllegalStateException : YouTubeServiceEntity not initialized with YouTubeThumbnailView 错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:55 24 4
gpt4 key购买 nike

我在我的 android 应用程序中使用 youtube api 在我的 RecyclerView 中加载视频的缩略图。以下是我在我的适配器中的实现:

private final Map<YouTubeThumbnailView, YouTubeThumbnailLoader> thumbnailViewToLoaderMap;

它为每个适配器元素保存 YouTubeThumbnailView 的加载程序。这是我们用于初始化 YouTubeThumbnailLoader(s) 的代码:

    YouTubeThumbnailLoader loader = thumbnailViewToLoaderMap.get(holder.thumbnail);
final String videoId = Utils.getYoutubeIdFromUrl(m.getYoutubeUrl());
holder.thumbnail.setTag(videoId);
if(loader != null) {
loader.setVideo(videoId);
}
}

当初始化 ViewHolder 的元素时,我按如下方式初始化缩略图加载器:

private void setupYoutubeThumbnail() {
thumbnail.initialize(RiyazApplication.applicationInstance
.getString(R.string.youtube_api_developer_key),
thumbnailListener);
thumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v.getTag() != null && itemClickListener != null) {
itemClickListener.onClickVideo(mList.get(getAdapterPosition()));
}
}
});

释放缩略图加载器的代码如下:

public void releaseThumbnailLoaders() {
final Set<YouTubeThumbnailView> keysSet = thumbnailViewToLoaderMap.keySet();
for(YouTubeThumbnailView view: keysSet) {
final YouTubeThumbnailLoader loader = thumbnailViewToLoaderMap.get(view);
if(loader != null) {
loader.release();
}
}
thumbnailViewToLoaderMap.clear();
}

在我的崩溃分析中,出现以下异常:

Fatal Exception: java.lang.IllegalStateException: YouTubeServiceEntity not initialized
at android.os.Parcel.readException(Parcel.java:1497)
at android.os.Parcel.readException(Parcel.java:1443)
at com.google.android.youtube.player.internal.l$a$a.a(Unknown Source)
at com.google.android.youtube.player.internal.o.a(Unknown Source)
at com.google.android.youtube.player.internal.p.(Unknown Source)
at com.google.android.youtube.player.internal.ac.a(Unknown Source)
at com.google.android.youtube.player.YouTubeThumbnailView$a.a(Unknown Source)
at com.google.android.youtube.player.internal.r.g(Unknown Source)
at com.google.android.youtube.player.internal.r$c.a(Unknown Source)
at com.google.android.youtube.player.internal.r$b.a(Unknown Source)
at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5052)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(NativeStart.java)

我不确定,为什么我会得到这个。有人可以帮忙吗?

最佳答案

将您的 initaizle 语句放在 try-catch 语句中,如下所示:

try {   

thumbnail.initialize(RiyazApplication.applicationInstance.getString(R.string.youtube_api_developer_key), thumbnailListener);
}
catch(IllegalStateException w){}

关于android - java.lang.IllegalStateException : YouTubeServiceEntity not initialized with YouTubeThumbnailView 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51569399/

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