Tuesday, 31 July 2018

java.lang.IllegalStateException: YouTubeServiceEntity not initialized with YouTubeThumbnailView

I am using youtube api in my android app to load thumbnails for videos in my RecyclerView. Following is my implementation in side my adapter:

private final Map<YouTubeThumbnailView, YouTubeThumbnailLoader> thumbnailViewToLoaderMap;

This holds the loaders for the YouTubeThumbnailView for each adapter element. This is the code we use for initialisation of the 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);
                    }
                }

When initialising the elements of the ViewHolder, I initialise the thumbnail loaders as follows:

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

and the code for releasing the thumbnail loaders is as follows:

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

In my crashalytics, I am getting the following exception:

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)

I am not sure, why am I getting this. Can anyone please help?



from java.lang.IllegalStateException: YouTubeServiceEntity not initialized with YouTubeThumbnailView

No comments:

Post a Comment