On Android, getting java.lang.NoClassDefFoundError: javax.inject.Provider

7,053 views
Skip to first unread message

James Moore

unread,
Mar 31, 2011, 9:14:45 PM3/31/11
to google-guice
What's this error trying to tell me? I'm playing with Guice on
Android, and I create a trivial injector like this:

Module m = new Module()
{
@Override
public void configure(Binder binder)
{
}
};
com.google.inject.Guice.createInjector(m);

(Not expecting this to do anything useful, of course)

And what I get is:

03-31 18:01:05.693: ERROR/AndroidRuntime(8374): FATAL EXCEPTION: main
03-31 18:01:05.693: ERROR/AndroidRuntime(8374):
java.lang.NoClassDefFoundError: javax.inject.Provider
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.java:
81)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.Key.<init>(Key.java:119)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.Key.get(Key.java:212)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.spi.Elements$RecordingBinder.bind(Elements.java:262)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.internal.InjectorShell
$RootModule.configure(InjectorShell.java:276)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:
223)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.spi.Elements.getElements(Elements.java:101)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.internal.InjectorShell
$Builder.build(InjectorShell.java:133)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:
103)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.Guice.createInjector(Guice.java:95)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.Guice.createInjector(Guice.java:72)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.google.inject.Guice.createInjector(Guice.java:62)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.banshee.Learn.onCreate(Learn.java:20)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1722)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
1784)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.os.Handler.dispatchMessage(Handler.java:99)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.os.Looper.loop(Looper.java:123)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
android.app.ActivityThread.main(ActivityThread.java:3839)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
java.lang.reflect.Method.invokeNative(Native Method)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
java.lang.reflect.Method.invoke(Method.java:507)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-31 18:01:05.693: ERROR/AndroidRuntime(8374): at
dalvik.system.NativeStart.main(Native Method)
03-31 18:01:05.740: WARN/ActivityManager(12695): Force finishing
activity com.banshee/.Learn

I'm using guice-3.0-no_aop.jar. I tried experimenting with adding
javax.inject.jar, but that didn't change anything.

Moandji Ezana

unread,
Apr 1, 2011, 2:47:52 AM4/1/11
to google...@googlegroups.com

Are you using Guice-noaop?

Moandji

--
www.moandjiezana.com

Sent from my phone

> --
> You received this message because you are subscribed to the Google Groups "google-guice" group.
> To post to this group, send email to google...@googlegroups.com.
> To unsubscribe from this group, send email to google-guice...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
>

James Moore

unread,
Apr 1, 2011, 10:49:01 AM4/1/11
to google...@googlegroups.com, Moandji Ezana
On Thu, Mar 31, 2011 at 11:47 PM, Moandji Ezana <mwa...@gmail.com> wrote:
> Are you using Guice-noaop?

Yes, guice-3.0-no_aop.jar from
http://code.google.com/p/google-guice/downloads/detail?name=guice-3.0-no_aop.jar&can=2&q=

Simone Tripodi

unread,
Apr 1, 2011, 1:52:10 PM4/1/11
to google...@googlegroups.com
Hi James,
for what I can see you just need to import the javax.inject APIs, if
you're a Maven user you just need to add the dependency[1] otherwise
download the jar and add it in the classpath.
HTH,
Simo

[1] http://mavencentral.sonatype.com/#artifactdetails%7Cjavax.inject%7Cjavax.inject%7C1

http://people.apache.org/~simonetripodi/
http://www.99soft.org/

James Moore

unread,
Apr 2, 2011, 2:23:06 PM4/2/11
to google...@googlegroups.com, Simone Tripodi
On Fri, Apr 1, 2011 at 10:52 AM, Simone Tripodi
<simone...@apache.org> wrote:
> Hi James,
> for what I can see you just need to import the javax.inject APIs, if
> you're a Maven user you just need to add the dependency[1] otherwise
> download the jar and add it in the classpath.

Thanks, that did the job.

Did this change between Guice 2.0 and 3.0? I just tried 2.0, and I
can take the same code, use the 2.0 jar, and it doesn't crash. The
3.0 jar crashes unless I also include the javax.inject-1.jar that
Simone pointed me to.

--
James Moore
ja...@restphone.com
http://jamesmoorecode.blogspot.com/

Sam Berlin

unread,
Apr 2, 2011, 2:33:07 PM4/2/11
to google...@googlegroups.com, James Moore, Simone Tripodi

Umed Khudoiberdiev

unread,
May 17, 2012, 5:37:15 PM5/17/12
to google...@googlegroups.com
try to add this library http://search.maven.org/remotecontent?filepath=javax/inject/javax.inject/1/javax.inject-1.jar into your project


пятница, 1 апреля 2011 г., 6:14:45 UTC+5 пользователь James Moore написал:
Reply all
Reply to author
Forward
0 new messages