6

I just started studying google-api-java-client on Android. Added next 3 libraries into project. (I don't use Maven.)

  • google-api-client-1.4.1-beta.jar
  • google-api-client-googleapis-1.4.1-beta.jar
  • google-api-client-googleapis-extensions-andr

And picked sample code to work with. In the sample, it used GoogleTransport which seems not available now.

HttpTransport transport = GoogleTransport.create();

So I changed it to NetHttpTransport(), found on the web.

import com.google.api.client.http.javanet.NetHttpTransport;
...
   HttpTransport transport = new NetHttpTransport();

But, I got exception.

05-24 15:54:33.310: ERROR/AndroidRuntime(4586): java.lang.NoClassDefFoundError: com.google.common.base.Preconditions
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:324)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.util.ClassInfo.of(ClassInfo.java:77)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.util.GenericData.<init>(GenericData.java:44)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.http.HttpHeaders.<init>(HttpHeaders.java:37)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.http.HttpTransport.<init>(HttpTransport.java:82)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at com.google.api.client.http.javanet.NetHttpTransport.<init>(NetHttpTransport.java:35)
05-24 15:54:33.310: ERROR/AndroidRuntime(4586):     at net.DailyTimer.test.MainActivity.onCreate(MainActivity.java:290)

What is wrong with this?

Valentin Rocher
  • 11,667
  • 45
  • 59
Tomcat
  • 1,405
  • 3
  • 22
  • 37
  • I'm using the example same line of code `HttpTransport transport = new NetHttpTransport();` but I'm getting a ClassCastException. Did you run into that at all? – Will Tate Jun 16 '11 at 20:05

1 Answers1

10

As you can see in the error, you have a class missing, coming from Guava. You can either download the guava lib and add it in your classpath, or use maven (or Ivy) to manage your dependencies for you.

Valentin Rocher
  • 11,667
  • 45
  • 59
  • Thank you for editing my poor question. And adding Guava fixed issue, thanks. I could not find out I need Guava. I will learn about maven later. – Tomcat May 24 '11 at 09:40
  • stupid question maybe but how do you see that com.google.common.base.Preconditions is coming from Guava ? – Hubert Nov 01 '12 at 10:56
  • I've been working with Guava for quite a time now, so I recognized it, but I think that just a Google search would have yielded the same answer :) – Valentin Rocher Nov 11 '12 at 07:42