I included a jar file in my Android project as explained in How can I use external JARs in an Android project?. With both methods described by MannyNS and Vinayak B. in this post I get the error "Could not find class 'test.libraryCalc.Calc" which is the class provided by the library. The following code illustrates the problem:
Example class provided via library: Calc.java
package test.libraryCalc;
public class Calc {
public int add(int a, int b){
return a + b;
}
}
LibraryTestActivity.java
package test.library;
import test.libraryCalc.Calc;
import android.app.Activity;
import android.os.Bundle;
public class LibraryTestActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calc calc = new Calc();
int c = calc.add(3, 4);
}
}
I exported the jar file containing Calc.java to LibraryTest\libs\calc.jar
and added a reference to it using the "Add JARs..." button in the Java Build Path of LibraryTest
The library shows up in the Referenced libraries in LibraryTest
LibraryTest has no build problems but when running it on the emulator the following is shown in LogCat:
12-27 14:01:33.965: E/dalvikvm(747): Could not find class 'test.libraryCalc.Calc', referenced from method test.library.LibraryTestActivity.onCreate
12-27 14:01:33.965: W/dalvikvm(747): VFY: unable to resolve new-instance 13 (Ltest/libraryCalc/Calc;) in Ltest/library/LibraryTestActivity;
12-27 14:01:33.995: D/dalvikvm(747): VFY: replacing opcode 0x22 at 0x0008
12-27 14:01:33.995: D/dalvikvm(747): VFY: dead code 0x000a-0013 in Ltest/library/LibraryTestActivity;.onCreate (Landroid/os/Bundle;)V
12-27 14:01:34.065: D/AndroidRuntime(747): Shutting down VM
12-27 14:01:34.065: W/dalvikvm(747): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-27 14:01:34.075: E/AndroidRuntime(747): FATAL EXCEPTION: main
12-27 14:01:34.075: E/AndroidRuntime(747): java.lang.NoClassDefFoundError: test.libraryCalc.Calc
12-27 14:01:34.075: E/AndroidRuntime(747): at test.library.LibraryTestActivity.onCreate(LibraryTestActivity.java:14)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Looper.loop(Looper.java:123)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-27 14:01:34.075: E/AndroidRuntime(747): at dalvik.system.NativeStart.main(Native Method)
12-27 14:06:34.170: I/Process(747): Sending signal. PID: 747 SIG: 9
What needs to be done to get this working? Thanks for all suggestions.
I think that the problem is that you try to add jar that contains Android code. You cannot do this. To include Android code you should create Android library. Simply create an Android project and in the project-properties Android section set that this is library project. After that you'll be able to add this library to your projects. For more about Android libraries you can read here.
Update: I've tried your code now. It works in my case. The only difference that I've made is during export of Jar I've checked Export Java source files and resources. Hope this will help you. Try it!
Related
When i'm trying to run my application i receive the error as The application Sample 2 (com.example.sample2) has stopped unexpectedly. Please try again Force close error. Logcat error is given below
02-07 03:46:52.292: I/Process(275): Sending signal. PID: 275 SIG: 9
02-07 03:47:01.045: D/AndroidRuntime(335): Shutting down VM
02-07 03:47:01.045: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-07 03:47:01.106: E/AndroidRuntime(335): FATAL EXCEPTION: main
02-07 03:47:01.106: E/AndroidRuntime(335): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.projectsample1/com.example.projectsample1.MainActivity}: java.lang.ClassNotFoundException: com.example.projectsample1.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.projectsample1-1.apk]
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-07 03:47:01.106: E/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 03:47:01.106: E/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:521)
02-07 03:47:01.106: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-07 03:47:01.106: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-07 03:47:01.106: E/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
02-07 03:47:01.106: E/AndroidRuntime(335): Caused by: java.lang.ClassNotFoundException: com.example.projectsample1.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.projectsample1-1.apk]
02-07 03:47:01.106: E/AndroidRuntime(335): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-07 03:47:01.106: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-07 03:47:01.106: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-07 03:47:01.106: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-07 03:47:01.106: E/AndroidRuntime(335): ... 11 more
02-07 03:52:01.252: I/Process(335): Sending signal. PID: 335 SIG: 9
Initially, this application was working well. But after a few days, it stopped working giving the above error. I don't seem to understand what is wrong. Please help me.
You have done one of two things:
Renamed your activity package or class name and not updated it in the manifest
or
Changed your manifest to reflect an activity that doesn't exist
Check your manifest against the fully qualified class name for that Activity. Make sure they match. Then go to Project -> Clean and clean your project.
I think, you declared Activity in AndroidManifes.xml, and register it as default to launch in your application. But, you have no Activity with this name as you declared in manifest. Just correct activity name in AndroidManifest.xml
Here is the error:
java.lang.ClassNotFoundException: com.example.projectsample1.MainActivity
The MainActivity class of the projectsample1 Application was not found.
Try to clear the dalvik-cache if you know how to do it.
Otherwise, re-install the application.
Or if you are the developer of the application, make sure to change the name of the class in the Manifest.xml file if you changed the name of the MainActivity class.
as I have read a java.lang.VerifyError in many cases hints to referencing
incompatible jar files which do not rely on the Android SDK.
My question is, whether there is a way to check,
which method calls in particular within the imported jar files are incompatible.
Is it possible to list the conflicts?
Like this I would like to check whether it is a lot of effort to make my ready made
java programme android compatible or not?
So far I only get an VerifyError and which file causes it.
But since it is a file referencing other stuff and having some code, I would like to know at which locations exactly there is the error.
EDIT:
Here you can see the log of the LogCat.
09-21 11:10:03.080: W/dalvikvm(1988): VFY: unable to resolve exception class 427 (L/codec/ContentAccessException;)
09-21 11:10:03.080: W/dalvikvm(1988): VFY: unable to find exception handler at addr 0x16
09-21 11:10:03.080: W/dalvikvm(1988): VFY: rejected Lsmb/LPP_SM;.start ()[Ljava/lang/String;
09-21 11:10:03.080: W/dalvikvm(1988): VFY: rejecting opcode 0x0d at 0x0016
09-21 11:10:03.080: W/dalvikvm(1988): VFY: rejected Lsmb/LPP_SM;.start ()[Ljava/lang/String;
09-21 11:10:03.080: W/dalvikvm(1988): Verifier rejected class Lsmb/LPP_SM;
09-21 11:10:03.080: D/AndroidRuntime(1988): Shutting down VM
09-21 11:10:03.080: W/dalvikvm(1988): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-21 11:10:03.110: E/AndroidRuntime(1988): FATAL EXCEPTION: main
09-21 11:10:03.110: E/AndroidRuntime(1988): java.lang.VerifyError: smb/LPP_SM
09-21 11:10:03.110: E/AndroidRuntime(1988): at com.example.androidtest.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:109)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.Activity.performCreate(Activity.java:5008)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.os.Looper.loop(Looper.java:137)
09-21 11:10:03.110: E/AndroidRuntime(1988): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-21 11:10:03.110: E/AndroidRuntime(1988): at java.lang.reflect.Method.invokeNative(Native Method)
09-21 11:10:03.110: E/AndroidRuntime(1988): at java.lang.reflect.Method.invoke(Method.java:511)
09-21 11:10:03.110: E/AndroidRuntime(1988): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-21 11:10:03.110: E/AndroidRuntime(1988): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-21 11:10:03.110: E/AndroidRuntime(1988): at dalvik.system.NativeStart.main(Native Method)
I have asked for a list of the problematic classes or function calls.
Here I believe I can only see, that the ContentAccessException is the only issue
not compatible with Android.
At least, if I comment that part within e.g. LPP_SM the error would vanish.
But this Exception is from one of my used libraries, which I cannot change.
Could there be more conflicts?
You should be able to track the problem by carefully reading the output of "adb logcat". You should be able to see the class that could not be found as well as the class that has the bad reference. Search for WARN/dalvikvm just before the exception.
There are a few more information on this thread : Android java.lang.VerifyError?
Are you in Debug mode or using proguard for a release ? the java.lang.VerifyError is due to a different compilator version, if you have any external jars that uses android class (like View) and your target sdk is different from the used one to generate the jar. You will find the class in the Log with error. Can you provide the complete error? If your are using proguard you can prevent preverification using -dontpreverify -dontoptimizeoption.
I have a simple android application which uses a modbus library ("jamod") on its build path. It crashes immediately as i run it. I have basically the same problem in this question: Getting "Caused by: java.lang.VerifyError:"
But i cannot really fix the problem. My application was working fine before, now no matter what i do it doesn't seem to work.
Below is logcat output. Thanks in advance.
08-09 14:36:47.753: W/dalvikvm(396): VFY: unable to find class referenced in signature (Lnet/wimpi/modbus/net/TCPMasterConnection;)
08-09 14:36:47.823: W/dalvikvm(396): VFY: unable to resolve exception class 510 (Lnet/wimpi/modbus/ModbusIOException;)
08-09 14:36:47.823: W/dalvikvm(396): VFY: unable to find exception handler at addr 0x18
08-09 14:36:47.854: W/dalvikvm(396): VFY: rejected Lcom/example/xmlparsertest/JavaModBusTcpDriver;.<init> (Ljava/lang/String;I)V
08-09 14:36:47.854: W/dalvikvm(396): VFY: rejecting opcode 0x0d at 0x0018
08-09 14:36:47.854: W/dalvikvm(396): VFY: rejected Lcom/example/xmlparsertest/JavaModBusTcpDriver;.<init> (Ljava/lang/String;I)V
08-09 14:36:47.854: W/dalvikvm(396): Verifier rejected class Lcom/example/xmlparsertest/JavaModBusTcpDriver;
08-09 14:36:47.854: D/AndroidRuntime(396): Shutting down VM
08-09 14:36:47.854: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-09 14:36:47.873: E/AndroidRuntime(396): FATAL EXCEPTION: main
08-09 14:36:47.873: E/AndroidRuntime(396): java.lang.VerifyError: com.example.xmlparsertest.JavaModBusTcpDriver
08-09 14:36:47.873: E/AndroidRuntime(396): at com.example.xmlparsertest.MainActivity.<init>(MainActivity.java:13)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.Class.newInstanceImpl(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.Class.newInstance(Class.java:1429)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.os.Looper.loop(Looper.java:123)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.reflect.Method.invoke(Method.java:521)
08-09 14:36:47.873: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-09 14:36:47.873: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-09 14:36:47.873: E/AndroidRuntime(396): at dalvik.system.NativeStart.main(Native Method)
One thing to double check you are doing is that the checkbox is ticked for the jar files in the "Order and Export" tab in the Build path window. That will include the library in the built APK.
Did you put the jamod jar file in the "libs" directory in Eclipse? If not it won't be bundled into your application even if it is on the path during compilation. This is a fairly new change.
I had a similar VFY, link and class def not found errors even though all of my libraries were in "LIB" folder and had added them in build path as well and ECLIPSE could find them easily in compile time, but when they were deployed on a real device, it gave problems.
Solution: Make sure your library files are placed in "libs" folder and not in "lib" or "library" in the ECLIPSE project.
This error (java.lang.VerifyError) comes when there are incompatible resources like interfaces/class/libs files, improper inheritances/encapsulation of static/instance level identifiers as variables/methods/arguments/class/files.
This issue is coming by simply violation of OOP design principles in the code. So the code rejected by verification process of jvm and throws verification error on runtime. If you closely look at the Error stacktrace, Instance of class-A(com.example.xmlparsertest.MainActivity) is being created by jvm stack [java.lang.Class.newInstanceImpl(Native Method)... java.lang.Class.newInstance...]. This class is referring or being reffered by other classes with violation of design principles which is causing the class to fail to get instantiated.
08-09 14:36:47.854: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-09 14:36:47.873: E/AndroidRuntime(396): FATAL EXCEPTION: main
08-09 14:36:47.873: E/AndroidRuntime(396): java.lang.VerifyError: com.example.xmlparsertest.JavaModBusTcpDriver
08-09 14:36:47.873: E/AndroidRuntime(396): at com.example.xmlparsertest.MainActivity.<init>(MainActivity.java:13)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.Class.newInstanceImpl(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.Class.newInstance(Class.java:1429)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.os.Looper.loop(Looper.java:123)
08-09 14:36:47.873: E/AndroidRuntime(396): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396): at java.lang.reflect.Method.invoke(Method.java:521)
08-09 14:36:47.873: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-09 14:36:47.873: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-09 14:36:47.873: E/AndroidRuntime(396): at dalvik.system.NativeStart.main(Native Method)
These warnings cannot be ignored because these warnings are causing the FATAL EXCEPTIONS. Dalvikvm Engineers have implemented the OOP principles as Sun Engineers Done. There are various blogs/forum where people says to ignore these warning. So do not ignore these warning and correct them especially for medical/banking/security field applications or that warning is causing to break the Application.
Do recheck your implemented OOP design principles (e.g. inheritances/encapsulation/polymorphism etc.) in the code. I was being asked to check and eliminate such errors on a big multi-module android application and i found many design violations.
First trigger to solve such issues make public/non-final everything related to class which is getting into FATAL ERROR. Once you solved, then implement your design principles one-by-one and you will get an error free appplication.
Thanks,
Vinod Bherwal (Android Architect).
I developed the project in Eclipse, then moved to IntelliJ IDEA CE 12, then moved back to the Eclipse. IDEA had converted it to eclipse project not correctly, so I imported project from existing source and added line
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
to the section. Ok, it compiles successfully, but generates a lot of strange errors for the classes written by me and then crashes.
LogCat output:
E/dalvikvm( 9673): Could not find class 'com.capsule.launcher.views.Screen', referenced from method com.capsule.launcher.views.Workspace$1.onPageSelected
W/dalvikvm( 9673): VFY: unable to resolve check-cast 458 (Lcom/capsule/launcher/views/Screen;) in Lcom/capsule/launcher/views/Workspace$1;
D/dalvikvm( 9673): VFY: replacing opcode 0x1f at 0x0010
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/CellLayout; (346)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/CellLayout;' failed
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/DockBar; (455)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/DockBar;' failed
W/dalvikvm( 9673): VFY: unable to find class referenced in signature (Lcom/capsule/launcher/views/DockBar;)
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/CellLayout; (346)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/CellLayout;' failed
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/DockBar; (455)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/DockBar;' failed
E/dalvikvm( 9673): Could not find class 'com.capsule.launcher.views.DockBar', referenced from method com.capsule.launcher.views.WorkspaceHolder.onLayout
W/dalvikvm( 9673): VFY: unable to resolve instanceof 456 (Lcom/capsule/launcher/views/DockBar;) in Lcom/capsule/launcher/views/WorkspaceHolder;
D/dalvikvm( 9673): VFY: replacing opcode 0x20 at 0x001b
D/AndroidRuntime( 9673): Shutting down VM
W/dalvikvm( 9673): threadid=1: thread exiting with uncaught exception (group=0x40d6e300)
E/AndroidRuntime( 9673): FATAL EXCEPTION: main
E/AndroidRuntime( 9673): java.lang.NoClassDefFoundError: com.capsule.launcher.views.DockBar
E/AndroidRuntime( 9673): at com.capsule.launcher.LauncherActivity.createWorkspace(LauncherActivity.java:116)
E/AndroidRuntime( 9673): at com.capsule.launcher.LauncherActivity.onCreate(LauncherActivity.java:58)
E/AndroidRuntime( 9673): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime( 9673): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 9673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 9673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 9673): at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 9673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 9673): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9673): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 9673): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 9673): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9673): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 9673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 9673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 9673): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 301): Force finishing activity com.capsule.launcher/.LauncherActivity
D/dalvikvm( 9673): GC_CONCURRENT freed 4207K, 20% free 19381K/23943K, paused 13ms+4ms, total 52ms
W/ActivityManager( 301): Activity pause timeout for ActivityRecord{418f0cd0 com.capsule.launcher/.LauncherActivity}
D/dalvikvm( 301): GC_CONCURRENT freed 1886K, 28% free 22076K/30279K, paused 4ms+9ms, total 99ms
W/ActivityManager( 301): Activity destroy timeout for ActivityRecord{418f0cd0 com.capsule.launcher/.LauncherActivity}
D/Finsky ( 7843): [1] 5.onFinished: Installation state replication succeeded.
It worked fine in IDEA and Eclipse before!
I don't know what happend to your project, but try in Eclipse: Project--> Clean--> YourProject
Clean and Build Your Project in Eclipse.Also check in Android Manifest file ,if launcher Activity is defined correctly with its package name.
Its not a good idea to use it like this(manually) rather we can export projects from IntelliJ IDEA to Eclipse in simple steps.
please follow this standard document for the above.
http://www.jetbrains.com/idea/webhelp/exporting-intellij-idea-project-to-eclipse.html
hope this will help you.
if you use librarys in your project , try in build path add to the library export
If you do have the old working eclipse project then copy/replace all the new code and jars to it, from the IntelliJ IDEA project. Remember to copy/replace only the code and jars not the IntelliJ IDEA specific settings files.
Right click on the project which has issues and select properties.
Select the appropriate Android build (1.1, 1.5 or 1.5 with google api) and say ok.
Again right click on the project and select "Android Tools > Fix Project Properties"
Fix the imports once (if required)
Refresh the project and you should be ready to go without any manual editing
Hope this helps.
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 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.