我要访问YouTube
YouTubeThumbnailView
中的android studio
视频的缩略图。
代码:
public static void thumbnailfunc(Activity context,final String VIDEO_ID, int ThumbnailID)
{
YouTubeThumbnailView thumbnail =context.findViewById(R.id.ThumbnailID);
thumbnail.initialize(API_KEY, new OnInitializedListener()
{
@Override
public void onInitializationSuccess(
YouTubeThumbnailView youTubeThumbnailView,
final YouTubeThumbnailLoader youTubeThumbnailLoader)
{
youTubeThumbnailLoader.setVideo(VIDEO_ID);
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener()
{
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s)
{
//need to release the loader!!!
youTubeThumbnailLoader.release();
}
@Override
public void onThumbnailError(
YouTubeThumbnailView youTubeThumbnailView,
YouTubeThumbnailLoader.ErrorReason errorReason)
{
//need to release the loader!!!
youTubeThumbnailLoader.release();
}
});
}
@Override
public void onInitializationFailure(
YouTubeThumbnailView youTubeThumbnailView,
YouTubeInitializationResult youTubeInitializationResult)
{
//handle error here
}
});
}
这是我得到的错误:
Caused by: java.lang.NullPointerException:
Attempt to invoke virtual method 'void
com.google.android.youtube.player.YouTubeThumbnailView.initialize(
java.lang.String,
com.google.android.youtube.player.YouTubeThumbnailView$OnInitializedListener)'
on a null object reference
答案 0 :(得分:0)
您的日志报告清楚地表明,Android Studio无法在布局中找到缩略图视图 R.id.ThumbnailID 。请检查!