2016-08-03 95 views
1

logcat的:

java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.google.api.services.youtube.YouTube$Videos$List 

异常:onError被称为在代码波纹管

IService mService = application.getIService(Constants.mYoutubeUrl); 
subscription = mService.getYoutubeVideos(Constants.mYoutubeKey ,Constants.mYoutubeChannelId) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .subscribeOn(application.defaultSubscribeScheduler()) 
       .subscribe(new Observer<YouTube.Videos.List>() { 
        @Override 
        public void onCompleted() { 

        } 

        @Override 
        public void onError(Throwable e) { 
         videoMvpView.showMessage(R.string.probleme_connection); 
        } 

        @Override 
        public void onNext(YouTube.Videos.List videos) { 
         videoMvpView.showVideos(videos); 
         videoMvpView.showSelectedVideo(((Video)videos.get(0)).getSnippet().getTitle()); 
        } 
       }); 

IService.java

public interface IService { 
@GET("/youtube/v3/search?part=snippet,id&order=date&maxResults=20") 
Observable<YouTube.Videos.List> getYoutubeVideos(@Query("key") String key, @Query("channelId") String channelId); 


class Factory { 
    public static IService create(String baseUrl) { 
     Retrofit retrofit = new Retrofit.Builder() 
       .baseUrl(baseUrl) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 
       .build(); 
     return retrofit.create(IService.class); 
    } 
} 

}

回答

0

这是必须使用YouTube.Videos.List类,如果不采取原始字符串转换响应它使用json2schema然后尝试用它来POJO,这可能帮助,如果你必须使用比你需要检查的结构YouTube.Videos.List类,如果你可以提供原始响应,它可能有助于解决问题

相关问题