Can't seem to get RoboGuice to work. Help?

1,580 views
Skip to first unread message

Graphene

unread,
Apr 12, 2012, 1:42:46 PM4/12/12
to roboguice
So i have been trying to get RoboGuice to work, but i can't seem to
get it.

The app works when my main Activity is just an Activity everything
works fine.
But when i change The Extends Activity To RoboActivity my app fails
with the logcat:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.MyFirstApp/com.MyFirstApp.Activities.MainActivity}:
java.lang.ClassNotFoundException:
com.MyFirstApp.Activities.MainActivity

Can someone please help me to get this to work, i know i am doing
something wrong but i can't seem to find out what.

I have a public Github repository: g...@github.com:Lordsauron/
MyFirstAndroidApp.git for the code that i have used.


Key Shin

unread,
Apr 12, 2012, 1:48:15 PM4/12/12
to roboguice
How are you including RoboGuice?
Which version of RoboGuice are you using (1.x, 2.x)

Including your modified source code would also help.

Andrew Toulouse

unread,
Apr 12, 2012, 2:04:58 PM4/12/12
to robo...@googlegroups.com
Make a libs/ directory, place the roboguice jar in it, then in Eclipse, open the libs folder, right click the RoboGuice jar, and add it to your build path. Then try extending from RoboActivity (or RoboFragmentActivity).

Also note that you need the Android Compatibility Library to use RoboGuice - you can download it from Google via the SDK Manager (look for "Extras" -> "Android Support"). You'll want to find that in your Android SDK directory (in a subfolder of extras somewhere), and also copy that to libs/ and add to build path.

If you're using RoboGuice 2.0 you don't need a custom Application class, you can just create a file roboguice.xml in res/values/ (so that'd be res/values/roboguice.xml) with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedResources">
    <string-array name="roboguice_modules">
        <item>com.MyFirstApp.AppModule</item>
    </string-array>
</resources>

And then create a class called "AppModule" (really, the name can be whatever you want, though) in the com.MyFirstApp package. This class should extend from com.google.inject.AbstractModule. This also means that you should have Guice 3.0 in your build path. Get the one with "no aop" - this AOP stuff won't work on Android.

Also, something to note - packages should usually be lowercase. Convention is often:
com.blah.package
ClassName
methodName
variableName

package names are usually prefixed with a reversed domain name, which is why you've got stuff like com.google.inject - it's google.com -> inject.

tl;dr: download RoboGuice, Guice, and the Android Compatibility Library jars, put in libs/, add to build path; try again.

--Andy

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

Graphene

unread,
Apr 12, 2012, 2:21:02 PM4/12/12
to roboguice
I have the roboguice-2.0-RC1.jar & guice-3.0-no_aop.jar in the eclips
assets directory, and have already added them to the build path. (They
appear in the virtual folder Referenced Libraries)

I have just added the xml but that didn't fix the problem :(

The naming thing should not prevent roboguice from working right? (i
will change)
> > I have a public Github repository: g...@github.com (mailto:g...@github.com):Lordsauron/
> > MyFirstAndroidApp.git for the code that i have used.
>
> > --
> > You received this message because you are subscribed to the Google Groups "roboguice" group.
> > To post to this group, send email to robo...@googlegroups.com (mailto:robo...@googlegroups.com).
> > To unsubscribe from this group, send email to roboguice+...@googlegroups.com (mailto:roboguice+...@googlegroups.com).

Andrew Toulouse

unread,
Apr 12, 2012, 2:23:36 PM4/12/12
to robo...@googlegroups.com
The assets directory is for files you want to be able to load in the app such as images or files, not for classes you want to add to the project. Asset files are literally stuffed in the APK. That's not what you want.

--Andy

To post to this group, send email to robo...@googlegroups.com.
To unsubscribe from this group, send email to roboguice+...@googlegroups.com.

Andrew Toulouse

unread,
Apr 12, 2012, 2:25:07 PM4/12/12
to robo...@googlegroups.com
Also, did you remember to create the module class?

--Andy

On Thursday, April 12, 2012 at 11:21 AM, Graphene wrote:

Graphene

unread,
Apr 12, 2012, 2:25:19 PM4/12/12
to roboguice
1. Adding assets to buildpath
2. I am using 2.0 RC1
3. the source code can be found on the Github: https://github.com/Lordsauron/MyFirstAndroidApp

Graphene

unread,
Apr 12, 2012, 2:29:52 PM4/12/12
to roboguice
I didn't know about the assets directory. on the TekPub tutorial they
just put the *.jar files in the assets directory so i just did that.
I did remeber to create the module class. (i would also expect an
other error message.. but mabe that is just me :S)

But i made an lib folder and put the jar files in there. but it still
gives me the same error :(

On Apr 12, 8:25 pm, Andrew Toulouse <toulo...@crunchyroll.com> wrote:
> Also, did you remember to create the module class?
>
> --Andy
>
>
>
>
>
>
>
> On Thursday, April 12, 2012 at 11:21 AM, Graphene wrote:
> > I have the roboguice-2.0-RC1.jar & guice-3.0-no_aop.jar in the eclips
> > assets directory, and have already added them to the build path. (They
> > appear in the virtual folder Referenced Libraries)
>
> > I have just added the xml but that didn't fix the problem :(
>
> > The naming thing should not prevent roboguice from working right? (i
> > will change)
>
> > On Apr 12, 8:04 pm, Andrew Toulouse <toulo...@crunchyroll.com (http://crunchyroll.com)> wrote:
> > > Make a libs/ directory, place the roboguice jar in it, then in Eclipse, open the libs folder, right click the RoboGuice jar, and add it to your build path. Then try extending from RoboActivity (or RoboFragmentActivity).
>
> > > Also note that you need the Android Compatibility Library to use RoboGuice - you can download it from Google via the SDK Manager (look for "Extras" -> "Android Support"). You'll want to find that in your Android SDK directory (in a subfolder of extras somewhere), and also copy that to libs/ and add to build path.
>
> > > If you're using RoboGuice 2.0 you don't need a custom Application class, you can just create a file roboguice.xml in res/values/ (so that'd be res/values/roboguice.xml) with the following contents:
>
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedResources">
> > >     <string-array name="roboguice_modules">
> > >         <item>com.MyFirstApp.AppModule</item>
> > >     </string-array>
> > > </resources>
>
> > > And then create a class called "AppModule" (really, the name can be whatever you want, though) in the com.MyFirstApp package. This class should extend from com.google.inject.AbstractModule. This also means that you should have Guice 3.0 in your build path. Get the one with "no aop" - this AOP stuff won't work on Android.
>
> > > Also, something to note - packages should usually be lowercase. Convention is often:
> > > com.blah.package
> > > ClassName
> > > methodName
> > > variableName
>
> > > package names are usually prefixed with a reversed domain name, which is why you've got stuff like com.google.inject - it's google.com (http://google.com) -> inject.

Andrew Toulouse

unread,
Apr 12, 2012, 2:36:14 PM4/12/12
to robo...@googlegroups.com
If you're using Android SDK v17+ it's got to be a "libs" directory. Google screwed up in letting people actually know about this.

--Andy

--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To post to this group, send email to robo...@googlegroups.com.
To unsubscribe from this group, send email to roboguice+...@googlegroups.com.

Graphene

unread,
Apr 12, 2012, 2:40:09 PM4/12/12
to roboguice
SON OF A B*&*&(*&^*^%&^$^$@#@!@#$, you have got to be kidding me F*#K.
that little f&ckup cost me about 16h changing sh&t. Thanx allot it
seems to have fixed the problem. the application's starts now. thank
you so much!!!!!

On Apr 12, 8:36 pm, Andrew Toulouse <toulo...@crunchyroll.com> wrote:
> If you're using Android SDK v17+ it's got to be a "libs" directory. Google screwed up in letting people actually know about this.
>
> --Andy
>
>
>
>
>
>
>
> On Thursday, April 12, 2012 at 11:29 AM, Graphene wrote:
> > I didn't know about the assets directory. on the TekPub tutorial they
> > just put the *.jar files in the assets directory so i just did that.
> > I did remeber to create the module class. (i would also expect an
> > other error message.. but mabe that is just me :S)
>
> > But i made an lib folder and put the jar files in there. but it still
> > gives me the same error :(
>
> > To post to this group, send email to robo...@googlegroups.com (mailto:robo...@googlegroups.com).
> > To unsubscribe from this group, send email to roboguice+...@googlegroups.com (mailto:roboguice+...@googlegroups.com).
Reply all
Reply to author
Forward
0 new messages