Unable to Instantiate Service: ClassNotFoundException

android, eclipse, java

Solution

Due to a recent update of the ADT plugin the library folder had to be changed to "libs" instead of lib. I came across it several times recently.

Problem

I've read about a hundred problems of the same category, but none helped. I had a working application, then refactored the package name, and it compiled and ran. A week later I come back to work on it and get the ClassNotFoundException on launch. Worse yet, if I checkout a previous commit from the repo (one before any refactoring, where everything worked) that project raises the same error on launch (except with a different package name). I've tried everything I can think of and I don't know how to track the problem down. I have done the obvious things: clean the project, delete it entirely and re-add it, run on a fresh device... I'm not sure what code would be helpful to debug, but here's the declaration in my manifest and the logcat output. If something else might be useful let me know. I'm really lost here. Crash: ``` E/AndroidRuntime( 515): FATAL EXCEPTION: main E/AndroidRuntime( 515): java.lang.RuntimeException: Unable to instantiate service co.mosic.mosic.CommunicationService: java.lang.ClassNotFoundException: co.mosic.mosic.CommunicationService E/AndroidRuntime( 515): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2237) E/AndroidRuntime( 515): at android.app.ActivityThread.access$1600(ActivityThread.java:123) E/AndroidRuntime( 515): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201) E/AndroidRuntime( 515): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 515): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 515): at android.app.ActivityThread.main(ActivityThread.java:4424) E/AndroidRuntime( 515): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 515): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) E/AndroidRuntime( 515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) E/AndroidRuntime( 515): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 515): Caused by: java.lang.ClassNotFoundException: co.mosic.mosic.CommunicationService E/AndroidRuntime( 515): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) E/AndroidRuntime( 515): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) E/AndroidRuntime( 515): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) E/AndroidRuntime( 515): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2234) E/AndroidRuntime( 515): ... 10 more ``` Manifest: ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="co.mosic.mosic" android:versionCode="1" android:versionName="1.0" > ... <service android:name=".CommunicationService" > <intent-filter> <action android:name="co.mosic.mosic.MStcServiceInet" /> </intent-filter> </service> ```

Original source