Android Activity ClassNotFoundException - tried everything Android Activity ClassNotFoundException - tried everything android android

Android Activity ClassNotFoundException - tried everything


I spent some time play with my own project, and I am able to replicate your problem and get exactly the same exception stack trace when trying to run my main project, so I think this could be the cause:

Just like what I thought, it is all about how you reference your Android library project in the Android main project, a simple Eclipse configuration settings.

The Wrong Way:
Right click main project, choose Properties -> Java Build Path -> Projects -> Add..., this add the Android library Project as a dependency project in Android main project's build path, this does not work. If all required Android-related resources are defined in main project, you will not get any error at compile time, but when run the application, you get the exception described in the question.

The Correct Way:
Right click main project, choose Properties -> Android, in the Library section, add your Android library project here. Check out official dev guide Referencing a library project. This should fix all your problem. Also note that you have to use relative path reference the actual Android library project, as stated in the Library Project - Development considerations.

Hope this helps.


i've tested the code that you've given , and it works fine.try changing the "extends SimonSaysActivity " to simply "extends Activity " and see for yourself that it works .

the reason that it doesn't work is either SimonSaysActivity doesn't extend Activity (which i don't think you've made this mistake) , or the order of the build path is wrong .

to go to the order of the build path , go to :

project->properties->Java build path->order and export .

my basic order is : project src , project gen , android 4.0.3 , android dependencies .

this problem usually occurs when you use libraries .


I've just refactored an app into a framework library and an application.

I'm not entirely sure what you are trying to say here, but the fact that you used the word "refactored" here leads me to believe that you are misunderstanding the concept of a library project.


What library projects are:

A library project is a development project that contains shared source code and resources. Other Android projects can reference the library project and include its compiled sources in their .apk files at compile time.

What library projects are not:

A library project differs from a standard Android project in that you cannot compile it directly to a single .apk file and run it on an Android device. You can't use an Android projects as a library project, and then have another Android project extend the library project. It doesn't work that way.


That said, I would investigate the structure of your library project and insure that you've set it up correctly. It's OK to use your library to store shared code/resources, but if your library is attempting to behave as if it were a separate .apk within the library project itself, then you've probably done something wrong. I believe a ClassNotFoundException would be thrown if this were the case. To fix the problem, I'd just build the library project from scratch, rather than attempting to convert the Android project to a library project. That'll prevent you from running into tiny, annoying bugs.

Feel free to post more code if you are still having trouble. You should also elaborate a bit more on the structure (and purpose) of your library project... why you decided to use one, how you created it, etc.