Thursday 8 November 2012

Referenced Projects and the ClassNotFoundException

You're running an Android application on device or on the emulator through Eclipse.
You get a ClassNotFoundException on a class that's in one of one of your referenced projects.

Well, what now? You can see the file right there. Why doesn't the app have that class?

There's a simple reason for this. It could be one of two issues.

One: You're including a basic Java project to your Android project

The fix:
Open your Android project properties and select Java Build Path in the left pane.
Select the Order and Export tab.
From there make sure that your referenced project has the checkbox enabled. This will put the classes into the final Android .apk file.





Two: You're including an Android library project to your Android project.

The fix:
Open your Android project properties on your Android library project.
Select Android in the left pane.
Make sure the Is Library checkbox is checked.



Open your Android project properties on your Android project.
Select Android in the left pane.
Click the Add... button on the right and select your library project in the dialog.

Now, clean and run your Android app again and no more ClassNotFoundExceptions should appear.

No comments:

Post a Comment