I try to use Google Contacts Data API on Android and more specifically the ContactsService class but the application crash as soon as I try to instantiate ContactsService class.
I do not have this problem with a normal Java application.
For example, below code is working fine
public class TestJava {
public static void main(String[] args) {
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
However, below Android app crashes (I put the permission for Internet in the manifest)
public class TestAndroidActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
Does anyone know if Google Contacts Data API is working on Android? Did I miss a permission in the manifest?
Thanks in advance.
Edit:
I used two projects in Eclipse to test above code: a Java project and an Android project.
Both projects share the same libraries and only the Android project is crashing.
Here the error message:
09-10 12:12:43.928: INFO/AndroidRuntime(326): NOTE: attach of thread 'Binder Thread #3' failed
09-10 12:12:44.409: WARN/dalvikvm(332): Unable to resolve superclass of Lcom/google/gdata/client/contacts/ContactsService; (1133)
09-10 12:12:44.459: WARN/dalvikvm(332): Link of class 'Lcom/google/gdata/client/contacts/ContactsService;' failed
09-10 12:12:44.459: ERROR/dalvikvm(332): Could not find class 'com.google.gdata.client.contacts.ContactsService', referenced from method test34.pkg.Tests34Activity.onCreate
09-10 12:12:44.469: WARN/dalvikvm(332): VFY: unable to resolve new-instance 1142 (Lcom/google/gdata/client/contacts/ContactsService;) in Ltest34/pkg/Tests34Activity;
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: replacing opcode 0x22 at 0x0008
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: dead code 0x000a-0016 in Ltest34/pkg/Tests34Activity;.onCreate (Landroid/os/Bundle;)V
09-10 12:12:44.609: DEBUG/AndroidRuntime(332): Shutting down VM
09-10 12:12:44.609: WARN/dalvikvm(332): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): FATAL EXCEPTION: main
09-10 12:12:44.639: ERROR/AndroidRuntime(332): java.lang.NoClassDefFoundError: com.google.gdata.client.contacts.ContactsService
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at test34.pkg.Tests34Activity.onCreate(Tests34Activity.java:15)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Looper.loop(Looper.java:123)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at dalvik.system.NativeStart.main(Native Method)
09-10 12:12:44.659: WARN/ActivityManager(59): Force finishing activity test34.pkg/.Tests34Activity
09-10 12:12:45.159: WARN/ActivityManager(59): Activity开发者_StackOverflow pause timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
09-10 12:12:55.548: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
I think you getting this type of error
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
Have you added google-collect-1.0-rc1.jar file? if not then I am sure you got the error, this is the dependent file.
you can download from this file from this site and download it and add in your project.
精彩评论