我得到了这个片段,它应该是来自youtube的某些视频的标题。
public static void getVids() {
try {
YouTubeService myService = new YouTubeService("mycompany-myapp-1");
String myFeed = "http://gdata.youtube.com/feeds/videos?start-index=1&max-results=25&vq=lizards&oi=spell";
printVideoFeed(myService, myFeed);
} catch (IOException ex) {
Toast toast = Toast.makeText(null, "Error "+ex.toString(), 5000);
toast.show();
} catch (ServiceException ex) {
Toast toast = Toast.makeText(null, "Error "+ex.toString(), 5000);
toast.show();
}
}
private static void printVideoFeed(YouTubeService service, String feedUrl) throws IOException, ServiceException {
VideoFeed videoFeed = service.getFeed(new URL(feedUrl), VideoFeed.class);
List<VideoEntry> allVideos = videoFeed.getEntries();
Iterator<VideoEntry> itAllVideos = allVideos.iterator();
String Titles = "";
while (itAllVideos.hasNext()){
VideoEntry oneVideo = itAllVideos.next();
TextConstruct oneVideoTitle = oneVideo.getTitle();
Titles = Titles + " | " + oneVideoTitle.toString();
}
Toast toast = Toast.makeText(null, "Working! " + Titles , 5000);
toast.show();
}
但是当我执行它时它崩溃了。下面是logcat说的:
08-05 17:33:30.203: INFO/dalvikvm(13832): Failed resolving Lcom/google/gdata/data/media/MediaSource; interface 1435 'Ljavax/activation/DataSource;'
08-05 17:33:30.207: WARN/dalvikvm(13832): Link of class 'Lcom/google/gdata/data/media/MediaSource;' failed
08-05 17:33:30.207: INFO/dalvikvm(13832): Failed resolving Lcom/google/gdata/data/media/BaseMediaSource; interface 452 'Lcom/google/gdata/data/media/MediaSource;'
08-05 17:33:30.207: WARN/dalvikvm(13832): Link of class 'Lcom/google/gdata/data/media/BaseMediaSource;' failed
08-05 17:33:30.207: WARN/dalvikvm(13832): Unable to resolve superclass of Lcom/google/gdata/data/media/MediaStreamSource; (435)
08-05 17:33:30.207: WARN/dalvikvm(13832): Link of class 'Lcom/google/gdata/data/media/MediaStreamSource;' failed
08-05 17:33:30.207: ERROR/dalvikvm(13832): Could not find class 'com.google.gdata.data.media.MediaStreamSource', referenced from method com.google.gdata.client.media.MediaService.getMediaResource
08-05 17:33:30.207: WARN/dalvikvm(13832): VFY: unable to resolve new-instance 453 (Lcom/google/gdata/data/media/MediaStreamSource;) in Lcom/google/gdata/client/media/MediaService;
08-05 17:33:30.207: DEBUG/dalvikvm(13832): VFY: replacing opcode 0x22 at 0x0013
08-05 17:33:30.207: DEBUG/dalvikvm(13832): VFY: dead code 0x0015-0039 in Lcom/google/gdata/client/media/MediaService;.getMediaResource (Ljava/net/URL;Lcom/google/gdata/util/ContentType;Lcom/google/gdata/data/DateTime;)Lcom/google/gdata/data/media/MediaSource;
08-05 17:33:30.210: INFO/dalvikvm(13832): Failed resolving Lcom/google/gdata/data/media/MediaSource; interface 1435 'Ljavax/activation/DataSource;'
08-05 17:33:30.210: WARN/dalvikvm(13832): Link of class 'Lcom/google/gdata/data/media/MediaSource;' failed
08-05 17:33:30.210: WARN/dalvikvm(13832): VFY: unable to find class referenced in signature (Lcom/google/gdata/data/media/MediaSource;)
08-05 17:33:30.210: INFO/dalvikvm(13832): Failed resolving Lcom/google/gdata/data/media/MediaSource; interface 1435 'Ljavax/activation/DataSource;'
08-05 17:33:30.210: WARN/dalvikvm(13832): Link of class 'Lcom/google/gdata/data/media/MediaSource;' failed
08-05 17:33:30.210: INFO/dalvikvm(13832): Could not find method com.google.gdata.data.media.MediaSource.getName, referenced from method com.google.gdata.client.media.MediaService.initMediaRequest
…
你认为可能是什么问题?
谢谢!
我也遇到过类似的问题。解决方案应该是用这里找到的JavaMail库替换您的JavaMail库(JavaMail for Android)。
直接来自YouTube API团队:"我的理解是Java Google Data客户端库目前与Android运行时环境不兼容。"
这个链接是我找到答案的地方,以及你看到的错误消息。