22

I have two android projects, ProjA requires ProjB (in Eclipse Properties > Java Build Path > Projects > Add > ProjB). Every thing compiles ok in Eclipse, but when I run ProjA I get an error:

Could not find method XXX, referenced from method YYY.

Where XXX - is the method from ProjB.

How can I fix the settings?

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • Just ran into this same situation - including classnotfound errors at runtime as the app started up. Solution: add the library project source folder to the build path! – Brad Hein Mar 23 '11 at 21:46
  • I have the same problem! And I have tried EVERYTHING: adding a Project reference (as Commonsware suggests), creating a JAR-fil and importing that to ProjA - nothing works! – Ted Dec 02 '11 at 00:15
  • 1
    You have two options. 1) Make ProjB the so called "Android Library" (see accepted answer) 2) If ProjB has no resources (layouts, drawbles, etc.) then you can make common Java project (non-android), and add the android.jar as external jar on Libraries tab in eclipse, and remove JRE from same tab... The android.jar can be found at path like this: C:\android-sdk-windows\platforms\android-3\android.jar – alex2k8 Dec 02 '11 at 15:06
  • 1
    visit this link: http://developer.android.com/guide/developing/projects/projects-eclipse.html – Fool Works Feb 22 '12 at 12:26

5 Answers5

34

I have a similar problem when using external jar (in my case openCSV). The reason I had a problem was due to a change in ADT 17 (or above). What I needed to do to resolve the problem was

  1. In Eclipse go to Properties -> Java build path -> Order and export.
  2. Mark my jar.
  3. Move jar to top of the list.

The solution was found in the following page which reference to a very good article.

Community
  • 1
  • 1
Ika
  • 1,456
  • 1
  • 15
  • 24
  • 1
    Cheers, I initially thought it was nothing to do with my external project. The error was saying class X couldn't be found by method Y however method Y was found in class X! I was thinking how can method X.Y() not know about the class it comes from? Then I realized that method X.Y() did infact interact with some data structures which down the line came from an external project. So I went to Order and Export and moved the Android Private Libraries to the top and voila! Point being though for any onlookers, if you don't think another project is involved.. are you sure? – mgibson Jul 16 '13 at 09:44
  • 1
    +1 I swear coding android applications will be impossible without SO. – Sydwell May 24 '14 at 11:37
  • I'm not sure this has to do with external projects? I get the error `Could not find method android.os.PowerManager.isInteractive, referenced...` – Luis A. Florit Sep 04 '14 at 01:08
3

Importing Class from External Jar, Android you can try the above link.. I suggest taking care of this "android only support 1.6 and not 1.7" in your library jar

Community
  • 1
  • 1
Satish
  • 320
  • 2
  • 9
1

Combine the two projects into one.

Or, have ProjB build a JAR file that ProjA includes.

Or, turn ProjB into a remote Service, with the method in question exposed via AIDL, and have ProjA bind to that service to use the method.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • As noted above, none of these suggestions work. I keep getting the error above of a NoClassDefFound error. But in compile-time everything looks fine... I have cleaned, restarted etc... nothing works. – Ted Dec 02 '11 at 00:16
1

You may want to look at your design, if you don't want to go with the answer by CommonsWare.

For example, you could call the second project from the first by using Intents, for example.

If there is code that is common to the two projects then you may want to pull that into a new project where you can include the files directly into both projects, but if the two are supposed to work together there are different ways in Android to allow Activities to call each other, or to pass information, and you may want to look at those.

James Black
  • 41,583
  • 10
  • 86
  • 166
0

I've experienced this problem with the new Android Gradle build system, I fixed it by running gradle clean and then building and installing again. Build systems are complex beasts and Google still has yet to solve the dependency problem perfectly.

satur9nine
  • 13,927
  • 5
  • 80
  • 123