2

One of my menu items in my application simply tries to invoke another activity (that belongs to a different project in the same workspace):

myActivity.startActivity(new Intent(myActivity, com.bill.the.App.class));

But that immediately results in an exception at runtime:

E/AndroidRuntime(3847): java.lang.NoClassDefFoundError: com.bill.the.App

Why?

What am I missing?

(the project compiles and build just fine, it's only at run time that this error occurs)

Bill The Ape
  • 3,261
  • 25
  • 44
  • do you have that second project (which you are trying to invoke by menu) already installed on your target/emulator at the moment when you launch your activity? Perhaps, the project (hence the classes in it) is not installed so the class can't be found. – avepr Feb 16 '12 at 02:05
  • @alex.veprik Yes, I have that second project installed (with the same package name as in this workspace but a different package name from the invoking application's). But... that installed second project was built on a different workspace. Does that matter? – Bill The Ape Feb 16 '12 at 02:11

4 Answers4

3

Just Open your AndroidManiFest.xml, and write following line in it before the </application> tag.

<activity android:name=".App"/>
Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • That didn't help, but I think that this is a necessary tip on the way to solving the problem (see my comment to @Rich). +1. – Bill The Ape Feb 16 '12 at 02:26
3

It could be that the project or library containing com.bill.the.App is included in compilation search path, but not included in the resulting apk file (that is deployed to the device). If you include the project or library containing com.bill.the.App using a wrong way, this can happen. Make sure that you include it by using Android Library Project (project properties -> Android) or by including the jar file in the project properties -> Java Build Path -> Libraries.

Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
  • I did reference it as a Library project in the calling application, but I didn't mark it as `IsLibrary` in its own properties because it can be a standalone application. I am now checking another direction: It is being called from a Library project, so perhaps the Library's manifest should include that `` and not only the application's manifest. +1 for now. – Bill The Ape Feb 16 '12 at 02:30
  • Nope. Even adding the `` to the Library project didn't help. This is getting weird. – Bill The Ape Feb 16 '12 at 02:33
  • 1
    Well, I played a little with those `project properties -> Android` settings (**Is Library** checkbox *and* the **Add Library** button), got some `Conversion to Dalvik format failed with error 1` but I quickly solved it thanks to [this answer](http://stackoverflow.com/a/8106366/1124861). Exception solved. – Bill The Ape Feb 16 '12 at 02:59
1

I had the same problem when importing an old Eclipse/ADT project (made of several projects AKA modules) to Android Studio (2021.3.1.17).

The solution was to right-click the app's module > Open Module Settings > Dependencies > (app's module) > + (Add Dependency) > 3 Module Dependency > Select the module/project that contains the missing class.

WebViewer
  • 761
  • 7
  • 21
0

The activity may not be registered in the manifest

Rich
  • 36,270
  • 31
  • 115
  • 154
  • In the manifest of the **invoking** application? If so, then you are right. It's not registered in the manifest. Let me check if registering it solves the problem... – Bill The Ape Feb 16 '12 at 02:12
  • Hmmm... I just tried that and it doesn't solve the problem. I actually added the `` just before the `` tag in the manifest of the invoking application and I am still getting this error. +1 Nevertheless. – Bill The Ape Feb 16 '12 at 02:25