I did the following:
- Create a working Android project (not a library or test project) in Eclipse. It has a single package called X with an activity X.A.
- Create a new Java package Y within the aforementioned project with at least one class Y.C.
- Call Y.C from within X.A (that is, call something in the new package from the original package that previously works).
- Build and run the Android project.
It builds fine, but throws NoClassDefFoundError on the first line using Y.C, saying it cannot find Y.C. When I Refactor -> Move Y.C into package X (so it is now X.C), the runtime exception is no longer thrown. What’s wrong?
Vague hint: I’ve read that similar problems can happen when the build-time and runtime classpaths get out of sync somehow, but I haven’t found yet how to troubleshoot or fix the issue.
In your
AndroidManifest.xmlwhen defining your activities you have to set the fully qualified class name for activities residing in a sub-package or even another package.A fully qualified class name would be like
com.example.my.cool.app.Activity. Alternatively when only working with sub-packages you can set it like thisandroid:name=".app1.AnotherActivity"when your base-package looks like thiscom.example.my.cool.