17

I have dug out an old android project that I was working on a few years ago and loaded it into a new eclipse install (latest ADT etc).

The project all compiles ok (after some minor tweaking), and the app starts fine, however, when i press a button to start the main activity i get the following stack trace:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.tmm.android.activities.GameActivity
    at com.tmm.android.activities.StartActivity.onClick(StartActivity.java:53)
    at android.view.View.performClick(View.java:2408)

Now the class in question (GameActivity) is one of my classes that is in the app, so I know thats not the problem - but I noticed a warning right at the top of the logcat:

Unable to resolve superclass of Lcom/tmm/android/activities/GameActivity; (33)
Link of class 'Lcom/tmm/android/activities/GameActivity;' failed

My class GameActivity extends another class that is part of a third-party jar that i have included in the project (included it in the 'libs' directory, and added it to the project build path in eclipse).

Can anyone advise what I might have done wrong, or anything that has changed in the ADT/etc that I might need to take account of (it was working fine when i last had it in Eclipse)

Cheers

rhinds
  • 9,976
  • 13
  • 68
  • 111
  • 1
    Sounds like there is a dependency that the superclass is relying on that is not installed. – Roy Hinkley Sep 04 '12 at 20:00
  • that did cross my mind, but it is the same jar as I used last time I started up the app, so seems strange that it would be different - unless the android libraries have been changed? Is there any easy way to debug what exactly is missing? – rhinds Sep 04 '12 at 20:06

3 Answers3

29

I had the same problem. I had a custom View class which called methods in an imported library. I was also getting the "Unable to resolve superclass" error when the app was trying to create my view (while trying to inflate a layout that referred to that custom View).

I resolved my problem, and I had a play around to determine what I think is the definitive answer.

(As at writing, I am using the Eclipse Android Tools R21).

If you are using an external jar

  • Copy it to your project's "libs" folder. The Android Tools should do the rest.

If the library you want to use is a separate project in your workspace.

  • In your library project: go into Properties->Android and check the "Is Library" checkbox.
  • In your app project: go into to Properties->Android and add the library project in the same section there (click "Add.."). Don't check "Is Library" here!

Some answers to this question say you need to go to Properties->Java Build Path->Projects and add the library project there. For normal Java projects you would do that, but it appears the Android Tools don't need or use that.

Finally, you will probably want to make sure the lib is included in your exported app

  • Go to Properties->Java Build Path->Order and Export and make sure the library is checked.
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • OMG A MILLION UPVOTES TO YOU SIR!!! Add Library... *facepalm. Normal Add project doesn't work for some strange reason. – Eric Apr 30 '13 at 23:58
  • 4
    Most important part is Go to Properties->Java Build Path->Order and Export and make sure the library is checked. Previously it was not required, seems from Tools R21 or R22 onwards its needed – Yasitha Waduge May 22 '13 at 06:06
  • Thank you. Run into annoying bug which cost me 10hours of work: support library was referenced from another project, on compile time everything was fine, but on runtime, the MainActivity wasn't found (Mainactivity was extended from a class in support library). – Indrek Kõue Feb 19 '14 at 21:04
  • Thanks for solving a problem I had been struggling with for hours. Adding the library project via `Properties > Android > Library > Add` did the trick for me – Cat Jun 04 '14 at 00:51
10

Ok, was a simple problem in the end..

Having added the 3rd party library to the build path, the export tab wasnt defaulted to export the jar (eclipse normal behaviour) - so the jar wasnt being included in the deployment..

got past that problem ok..

rhinds
  • 9,976
  • 13
  • 68
  • 111
0

I had the same problem, I tried to check the Android Private Libraries under Order and Export and it didn't work for me. So then I noticed that my libs folder wasn't referenced under the Java Build Path, I just added it to Libraries and that is it...

DenninDalke
  • 161
  • 1
  • 4