Search code examples
javagdata-api

google data api for youtube


I'm trying to run the sample program, which comes with Google Data API. I get a runtime error at following line

YouTubeService myService = new YouTubeService("gdataSample-YouTube-1");

The error is the following:

run:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
        at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
        at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
        at com.google.gdata.client.Service.<clinit>(Service.java:532)
        at YouTubeReadonlyClient.main(YouTubeReadonlyClient.java:713)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

I tried both Google Data API versions 1.35.0 and 1.35.1, and I get the same error in both cases.


Solution

  • Looks like you don't have the collections library in your class path.

    It's in the gdata/java/deps directory in the zip file. Include the google-collect-1.0-rc1.jar file in your classpath and you should be fine. (You may also need jsr305.jar - I'm not sure.)