Simple android application with roboguice throwing exceptions

早过忘川 提交于 2019-12-02 05:51:44

问题


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.


回答1:


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




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!