如何使用 roboguice 制作简单的 android 应用程序来注入 textView?
我是依赖注入和 roboguice 的初学者。我只是希望能够在我的应用程序中注入视图和资源。问题是,当我使用 RoboActivity 扩展我的类时,我收到 ClassNotFoundException。
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);
}
这是堆栈跟踪:
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.ActivityThread.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
...
和我的清单
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>
我认为我的依赖关系很好,因为我可以看到 guice、roboguice 等的 jar 文件。 我尝试按照文档下载示例代码,但对我来说太复杂了。 我不知道我错过了什么。
感谢您的帮助。
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.ActivityThread.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在提交一个新答案,因为 RoboGuice 2.0 改变了它的工作方式。现在,在 res/values/ 中创建一个名为 roboguice.xml 的 XML 文件。在那里列出您的模块,如下所示:
另一个示例。
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:
Another example.
您没有正确扩展 RoboApplication。请考虑阅读完整的RoboGuice 安装教程
You're not properly extending RoboApplication. Please consider going through the complete RoboGuice installation tutorial
我遵循手册并使用了正确的命名约定,它起作用了!
尽管
MyApplication.java 中扩展 RoboApplication 的这一行有错误并表示删除 @Override,当我删除 @Override 时,它表示它与 RoboApplication 中的另一个方法冲突。我不知道为什么。
I followed the manual and used proper naming conventions and it worked!
although this line
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.