2

I am a bit new to Android development so bear with me.

I've already reviewed this MapView: Could not find class A referenced from method B and this Could not find method XXX, referenced from method YYY

but they do not help solve my issue.

I am getting the error reported in my question title when trying to run my app. My app requires a java project that I pulled from Github, which itself required a handful of jar files to compile on its own. I have the java project compiled, and Eclipse makes my android project appear to be compiled, but it isn't working on my phone.

I tried the following, all leading to the same result:

  • referenced the java library directly using the java build path
  • built an android project library which references the java library directly using the java build path, then adding the android project library to my projects android library path
  • built an android project library which references a jar I built from the java library, then adding the android project library to my projects android library path
  • built a jar from the java library, then adding the jar to the build path of my android project

the end result is always the same, my program compiles but when I try to run it crashes saying "could not find class "class from the GitHub project" referenced from "my main activity method"

Could anyone throw a bone?

Logcat

 12-14 11:08:49.792: I/Process(5538): Sending signal. PID: 5538 SIG: 9 12-14 11:09:56.722: D/szipinf(5626): Initializing inflate state 12-14 11:09:56.732: E/dalvikvm(5626): Could not find class 'gmusic.api.impl.GoogleSkyJamAPI', referenced from method com.example.gpmx.MainActivity.runGoogleAPI 12-14 11:09:56.732: W/dalvikvm(5626): VFY: unable to resolve new-instance 445 (Lgmusic/api/impl/GoogleSkyJamAPI;) in Lcom/example/gpmx/MainActivity; 12-14 11:09:56.732: D/dalvikvm(5626): VFY: replacing opcode 0x22 at 0x0000 12-14 11:09:56.732: D/dalvikvm(5626): VFY: dead code 0x0002-0036 in Lcom/example/gpmx/MainActivity;.runGoogleAPI (Ljava/lang/String;Ljava/lang/String;)V 12-14 11:09:56.812: D/AndroidRuntime(5626): Shutting down VM 12-14 11:09:56.812: W/dalvikvm(5626): threadid=1: thread exiting with uncaught exception (group=0x40018560) 12-14 11:09:56.812: E/AndroidRuntime(5626): FATAL EXCEPTION: main 12-14 11:09:56.812: E/AndroidRuntime(5626): java.lang.NoClassDefFoundError: gmusic.api.impl.GoogleSkyJamAPI 12-14 11:09:56.812: E/AndroidRuntime(5626): at com.example.gpmx.MainActivity.runGoogleAPI(MainActivity.java:63) 12-14 11:09:56.812: E/AndroidRuntime(5626): at com.example.gpmx.MainActivity.onResume(MainActivity.java:36) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.Activity.performResume(Activity.java:3832) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2231) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2256) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1789) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread.access$1500(ActivityThread.java:123) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.os.Handler.dispatchMessage(Handler.java:99) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.os.Looper.loop(Looper.java:130) 12-14 11:09:56.812: E/AndroidRuntime(5626): at android.app.ActivityThread.main(ActivityThread.java:3835) 12-14 11:09:56.812: E/AndroidRuntime(5626): at java.lang.reflect.Method.invokeNative(Native Method) 12-14 11:09:56.812: E/AndroidRuntime(5626): at java.lang.reflect.Method.invoke(Method.java:507) 12-14 11:09:56.812: E/AndroidRuntime(5626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 12-14 11:09:56.812: E/AndroidRuntime(5626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 12-14 11:09:56.812: E/AndroidRuntime(5626): at dalvik.system.NativeStart.main(Native Method) 

One more piece of information, if this helps. The java project I am using depends on various apache and google jars, which are in the java projects "lib" (not "libs") folder. Is this a problem when creating a jar?

Final update: It turned out that there was a lesson learned. At least with my configuration, all of the jars I needed in the android library had to be at the same directory level, that is, just under "libs". I have a couple of required jars, like apaches common.io jar within it's own directory under "libs", this was causing a problem.

2
  • 1
    Please post the entire LogCat stack so we can help. Commented Dec 14, 2012 at 16:26
  • possible duplicate of NoClassDefFoundError Android Commented Dec 10, 2013 at 14:40

3 Answers 3

3

See this SO post for correctly importing an existing project into Eclipse...

The most useful post seems to be:

  1. File->Import->General->Existing Projects into Workspace, Next
  2. Select root directory: /path/to/project
  3. Projects->Select All
  4. UNCHECK both "Copy projects into workspace" and "Add project to working sets"
  5. Finish

To add it as a library for another project, see this link from the Android dev site.

  1. In the Package Explorer, right-click the library project and select Properties.
  2. In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
  3. Select the "is Library" checkbox and click Apply.
Sign up to request clarification or add additional context in comments.

4 Comments

already tried creating an android project library, as mentioned. Are you saying I might not have run through the procedures correctly? Because I followed the android documentation that you mentioned to the letter.
Can you link to the library project youre using?
yes, the android library was added to my projects library list. In my method of adding the jar, the jar is view able under the android dependencies.
although I already tried this, it appeared that there were a handful of issues with my program the made it look like there was just a single issue. The android documented way of created an android library eventually worked out for me. thanks.
3

I had the same issue. And finally found the solution.

The java project you imported should be built when you build your android project.

Java build path -> Order and Export, check the java project and then rebuild your android project.

Comments

0

I had the same problem after importing OSMDroid into my app. I checking the LogCat output, which showed that the Dex loader couldn't find a particular Class (GeoPoint) in OSMDroid. I realised that there were no class files in the bin folder, i.e. it hadn't been compiled. The reason was that my import had put the source into a library called "org", rather than into "src". Moving it into "src" and rebuilding OSMDroid generated the proper Class files in "bin" and all now works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.