开发者

How to make simple android app with roboguice that injects a textView?

I'm a beginner in dependency injection and roboguice. I just want to be able to inject views and resources in my app. The problem is, I get a ClassNotFoundException when I extend my class with RoboActivity.

package tes.tes;
//imports
public class test extends RoboActivity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
}

Here's the stacktrace:

  06-09 13:54:08.887: ERROR/AndroidRuntime(495): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{tes.tes/tes.tes.test}:java.lang.ClassNotFoundException: tes.tes.test in loader dalvik.system.PathClassLoader[/data/app/tes.tes-1.apk]
  06-09 13:54:08.887: ERROR/AndroidRuntime(495):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
  06-09 13:54:08.887: ERROR/AndroidRuntime(495):     at android.app.Activi开发者_开发问答tyThread.handleLaunchActivity(ActivityThread.java:2679)
...
  06-09 13:54:08.887: ERROR/AndroidRuntime(495): Caused by: java.lang.ClassNotFoundException: tes.tes.test in loader dalvik.system.PathClassLoader[/data/app/tes.tes-1.apk]
  06-09 13:54:08.887: ERROR/AndroidRuntime(495):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243
...

and my manifest

coding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="tes.tes"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".test"
                  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 think my dependencies are fine since I can see the jar files for guice, roboguice, etc.. I tried following the documentation and downloading the sample code but it was too complicated for me. I don't know what I'm missing.

Thanks for the help.


I'm submitting a new answer because RoboGuice 2.0 has changed the way this works. Now, create an XML file in res/values/ named roboguice.xml. List your modules there, like so:

<?xml version="1.0" encoding="utf-8"?>
  <resources> 
    <string-array name="roboguice_modules">
    <item>com.example.CustomRenderModule</item>
    <item>com.you.yourmodule.TexModule</item>
  </string-array>
</resources>

Another example.


You're not properly extending RoboApplication. Please consider going through the complete RoboGuice installation tutorial


I followed the manual and used proper naming conventions and it worked!

although this line

@Override
protected void addApplicationModules(List<Module> modules) {
    modules.add(new MyModule());
}

in MyApplication.java which extends RoboApplication has errors and says remove @Override and when I remove the @Override it says it clashes with another method located in RoboApplication. I dont know why.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜