小部件 - 无法实例化接收器
我知道有人问过类似的问题,但没有一个对我有帮助。如果有人向我指出有解决方案的链接,我会非常高兴。无论如何,每次我在 Android 模拟器上安装正在开发的小部件时,我都会收到错误。
错误状态
ERROR/AndroidRuntime(866): java.lang.RuntimeException: 无法实例化接收器 com.ifractal.firstwidget.FirstWidget: java.lang.NullPointerException
这是相关代码
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ifractal.firstwidget"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".FirstWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIGET_ENABLE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/provider"
/>
</receiver>
</application>
这是我在 Eclipse 中的项目布局(以显示文件在那里)
我尝试使用不同的名称、清理/构建和其他一些内容重新创建项目,但是没有任何效果。我感谢您能给我的任何帮助,并愿意在需要时提供更多信息。谢谢。
I know similar questions have been asked but none have been helpful to me. If I were pointed to a link that has a solution I would be more than pleased. Anyway, I am getting an error every time I install a widget I am developing on my Android Emulator.
The error states
ERROR/AndroidRuntime(866): java.lang.RuntimeException: Unable to instantiate receiver com.ifractal.firstwidget.FirstWidget: java.lang.NullPointerException
Here is the relevant code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ifractal.firstwidget"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".FirstWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIGET_ENABLE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/provider"
/>
</receiver>
</application>
and here is my project layout in eclipse (to show that files are there)
I have tried recreating the project with a different name, cleaning/building, and a few other things but nothing has worked. I appreciate any help that you can give me and am willing to provide additional info if needed. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
清单对我来说看起来不错。您在 FirstWidget 中获得了 NPE,因此您需要查看该类。检查堆栈跟踪并查看抛出异常的具体位置。可能是构造函数吗?
The manifest looks fine to me. You get a NPE in FirstWidget, so you need to look into that class. Check the stack trace and see where exactly the exception is thrown. Could it be the constructor?
检查您的应用程序小部件类不是抽象的。
下面是一个典型的应用程序小部件类声明:
Check that your app widget class is not abstract.
Below is a typical app widget class declaration: