RoboGuice – Pitfall – RuntimeException on Activities

Last weekend, I started developing a application to sync OpenStreetMap contacts into my Android devices.

Wanting to avoid boilerplate code, and to experiment a little with Dependency Injection in Android, i based my work on RoboGuice. I think I followed all the example code, but my activities would simply crash with a RuntimeException on startup.

Since finding the root cause of this problem was not as trivial as I wished it to be, I decided to write this up as an article for myself and of course for all the other Android developers out there who don’t want to waste time hunting this issue when they could be gold-plating their apps 🙂

To cut to the core of the problem: If your activity is throwing this:

E/AndroidRuntime( 246): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 246): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.gurkensalat.osm.osmsync/com.gurkensalat.osm.osmsync.HelloAndroidActivity}: java.lang.ClassCastException:
E/AndroidRuntime( 246): at

maybe you need to declare your actual application class type in AndroidManifest.xml:

<application android:icon="@drawable/icon"

4 thoughts to “RoboGuice – Pitfall – RuntimeException on Activities”

  1. No big problem, at learned a lot about how Activity launching in Android really happens and how to debug that…

    Any ETA on roboguice 1.2 ? At this moment, all I see in the source repository is still 1.2-SNAPSHOT.

  2. What I don’t understand is why the Astroboy example doesn’t have this… or am I missing something? I can’t find this anywhere in the documentation, so if it’s there, it might be helpful if it were made more obvious.

Leave a Reply

Your email address will not be published. Required fields are marked *