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: android.app.Application
E/AndroidRuntime( 246): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
...
maybe you need to declare your actual application class type in AndroidManifest.xml:
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:name="roboguice.application.RoboApplication">
...
</application>
Sorry that was so hard to track down. Luckily this will no longer be necessary in RoboGuice 1.2!
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.
Not yet, but I’m hoping to get a beta out this month. Keep an eye on the forum for more info.
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.