我是 android 编程的新手,对出现的意外错误有点恼火。
我正在尝试制作一个有两个按钮并从教程开始的小部件。我在路上遇到了一些颠簸,但它的表现相当不错。现在我正在尝试调整小部件的高度和宽度并尝试添加更多组件。但我不断收到此错误:
10-24 09:33:40.941: E/AndroidRuntime(280): FATAL EXCEPTION: main
10-24 09:33:40.941: E/AndroidRuntime(280): java.lang.RuntimeException: Unable to instantiate receiver com.example.world.knowledge.agenda.MainActivity: java.lang.ClassNotFoundException: com.example.world.knowledge.agenda.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.world.knowledge.agenda.widget-1.apk]
10-24 09:33:40.941: E/AndroidRuntime(280): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.os.Looper.loop(Looper.java:123)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-24 09:33:40.941: E/AndroidRuntime(280): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 09:33:40.941: E/AndroidRuntime(280): at java.lang.reflect.Method.invoke(Method.java:521)
10-24 09:33:40.941: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-24 09:33:40.941: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-24 09:33:40.941: E/AndroidRuntime(280): at dalvik.system.NativeStart.main(Native Method)
10-24 09:33:40.941: E/AndroidRuntime(280): Caused by: java.lang.ClassNotFoundException: com.example.world.knowledge.agenda.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.world.knowledge.agenda.widget-1.apk]
10-24 09:33:40.941: E/AndroidRuntime(280): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-24 09:33:40.941: E/AndroidRuntime(280): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-24 09:33:40.941: E/AndroidRuntime(280): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-24 09:33:40.941: E/AndroidRuntime(280): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2780)
10-24 09:33:40.941: E/AndroidRuntime(280): ... 10 more
看来我为解决这个问题所做的所有努力都是徒劳的。也许你们中的一个人知道我该如何解决这个问题。(请尝试写下“虚拟证明”,这对我来说都是全新的 :))
这是我的安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.world.knowledge.agenda.widget"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"/>
<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="true">
<!-- this activity will be called, when we fire our self created ACTION_WIDGET_CONFIGURE -->
<activity android:name="com.example.world.knowledge.agenda.ClickOneActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="com.example.world.knowledge.agenda.MainActivity.ACTION_WIDGET_CONFIGURE"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Broadcast Receiver that will process AppWidget updates -->
<receiver android:name=".MainActivity"
android:label="@string/app_name"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<!-- Broadcast Receiver that will also process our self created action -->
<action android:name="com.example.world.knowledge.agenda.MainActivity.ACTION_WIDGET_RECEIVER"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/button_widget_provider" />
</receiver>
</application>
</manifest>
也许解决方案非常简单,但在此先感谢:)