尝试从YouTube获取数据时Android会崩溃?

时间:2011-08-05 14:43:07

标签: java android youtube-api

我收到了这个片段,它应该是来自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

...

您认为可能是什么问题?

谢谢!

2 个答案:

答案 0 :(得分:2)

我有类似的问题。解决方案应该是使用here(JavaMail for Android)替换JavaMail库。

答案 1 :(得分:1)

直接来自YouTube API团队:“我的理解是Java Google数据客户端库目前与Android运行时环境不兼容。”

This link是我找到答案以及您看到的错误消息的地方。