I have a very simple application that works but when i add roboguice it throws
java.lang.RuntimeException: Unable to instantiate application com.MyFirstApp.MyFirstApplication: java.lang.ClassNotFoundException: com.MyFirstApp.MyFirstApplication
The application class:
public class MyFirstApplication extends RoboApplication {
@Override
protected void addApplicationModules(List<Module> modules) {
//modules.add(new DefaultModule());
}
}
The MainActivity:
public class MainActivity extends RoboActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the manifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyFirstApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="MyFirstApplication">
<activity
android:name="com.MyFirstApp.Activities.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have put guice-2.0-no_aop.jar and roboguice-1.1.3.jar in the assets folder and added them to the buildpath.
when i remove the robo part it works fine. can anyone tell me what i did wrong.
Well i found out what the problem was. i was using SDK v17+ and in that version external library's need te be placed in a "libs" folder and only in the libs folder. so all the tutorial's i found where they just put it in the assets folder where wrong.
Link to where i got the answer i was looking for: http://groups.google.com/group/roboguice/browse_thread/thread/474116b052050ae2
First of all, extending from RoboApplication is a RoboGuice 1.x thing, you should really be using RoboGuice 2.0 (where you no longer need to do that). Now, for your exception, is your Application class really at com.MyFirstApp.MyApplication? If not, you would need to update the name attribute to match.
来源:https://stackoverflow.com/questions/10065123/simple-android-application-with-roboguice-throwing-exceptions