【问题标题】:No launcher activity found! Can't get widget to work未找到启动器活动!无法让小部件工作
【发布时间】:2013-10-05 17:19:36
【问题描述】:

我创建了一个包含以下类和 xml 文件的应用小部件: AFBWidget.java

WidgetConfig.java(用户在小部件布局中显示的文本字段中输入内容的配置屏幕)

widget.xml(实际小部件的布局)

widgetconfig.xml(与widgetconfig.java相同((除了它是实际的布局)))

widget_stuff.xml(android appwidget 提供者)

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

<receiver android:name=".AFBWidget" android:label="@string/app_name">
<intent-filter>
    <action android:name="android.appwidet.action.APPWIDGET_UPDATE"/>
</intent-filter>

    <meta-data android:name="android.appwidget.provider"
    android:resource="@xml/widget_stuff"/>

</receiver>

<activity android:name=".WidgetConfig" android:label="@string/app_name">
<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/> 
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".widget" 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>

最初,我没有 .widget 活动,也没有

            <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

要么,所以我收到错误“未找到 laucher 活动!”。因此,为了解决这个问题,我将启动器添加到我的 appwidget 配置中并修复了错误,但随后小部件将停止工作并强制关闭模拟器。

我的问题是我不知道将启动器放在什么活动上以使小部件工作而不会崩溃。

新错误:

10-06 08:58:29.448: D/AndroidRuntime(6994): Shutting down VM
10-06 08:58:29.448: W/dalvikvm(6994): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
10-06 08:58:29.458: E/AndroidRuntime(6994): FATAL EXCEPTION: main
10-06 08:58:29.458: E/AndroidRuntime(6994): java.lang.RuntimeException: Unable to instantiate receiver com.example.awesomefilebuilderwidget.AFBWidget: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2012)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.app.ActivityThread.access$2400(ActivityThread.java:135)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1101)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.os.Looper.loop(Looper.java:150)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.app.ActivityThread.main(ActivityThread.java:4333)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at java.lang.reflect.Method.invokeNative(Native Method)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at java.lang.reflect.Method.invoke(Method.java:507)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at dalvik.system.NativeStart.main(Native Method)
10-06 08:58:29.458: E/AndroidRuntime(6994): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.AFBWidget in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk]
10-06 08:58:29.458: E/AndroidRuntime(6994):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-06 08:58:29.458: E/AndroidRuntime(6994):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2003)
10-06 08:58:29.458: E/AndroidRuntime(6994):     ... 10 more
10-06 08:58:36.535: W/dalvikvm(7066): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    3 天后我终于修好了!好的,确实是因为我的两个 java 类在默认包中。所以为了解决这个问题,由于我的类是通过不同的包访问的,我创建了一个新的包,它是我的应用程序(com.example.awesomefilebuilderwidget),然后将类移到那里,现在它可以正常工作了! :DD 谢谢你所做的一切,我真的很感激它! – 用户 1628978

    【讨论】:

      【解决方案2】:

      如果您只想创建没有任何小部件,我们将其称为“主”活动,则无需为您的配置活动声明意图和类别过滤器。您只需要为动作android.appwidget.action.APPWIDGET_CONFIGURE 指定意图过滤器。当用户将小部件添加到主屏幕时,将启动此活动。您还需要使用以下属性在您的 appwidget-provider xml 文件中声明此活动android:configure

      因此,在您的情况下,清单应如下所示:

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.awesomefilebuilderwidget"
      android:versionCode="1"
      android:versionName="1.0" >
      
      <uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="18" />
      
      <application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" >
      
      <receiver android:name=".AFBWidget" android:label="@string/app_name">
      <intent-filter>
          <action android:name="android.appwidet.action.APPWIDGET_UPDATE"/>
      </intent-filter>
      
          <meta-data android:name="android.appwidget.provider"
          android:resource="@xml/widget_stuff"/>
      
      </receiver>
      
      <activity android:name=".WidgetConfig" android:label="@string/app_name">
      <intent-filter>
          <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>     
      </intent-filter>
      
      </activity>   
      
      </application>
      
      </manifest>
      

      在你的 widget_stuff.xml 中:

      <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"       
          //put your config data here
          android:configure="com.example.awesomefilebuilderwidget.WidgetConfig" 
      </appwidget-provider>
      

      【讨论】:

      • 谢谢。但是现在当我在我的设备上运行我的小部件时,该小部件没有显示在要放在主屏幕上的可用小部件列表中,而且我仍然收到“未找到启动器活动!”的错误!
      • 我可以通过将运行配置中的启动操作设置为我的 WidgetConfig 来修复此错误。但是,该小部件不会显示在设备上的小部件列表中,但会显示在应用程序管理器中。
      • 我进行了更深入的搜索,当您尝试从 Eclipse(或其他 IDE)启动应用程序时,您似乎会收到此错误。从 Eclipse 启动应用程序时,它会搜索您的清单并查找可以启动的活动(使用适当的意图 filetr)。好吧,由于您的小部件没有这样的“可启动”活动,您会看到此警告。要删除它,只需在 Eclipse 中为您的项目打开启动配置,然后在 Android 选项卡下的 Launch Action 部分选择 Do Nothing。这将阻止 eclipse 尝试为您的应用运行任何默认活动。
      • 谢谢,是的,修复了错误!但是现在,当我尝试将小部件放在我的设备上时,我得到了一串新的错误。如果您不介意快速查看它们,我会很高兴。 (更新答案)
      • 我还修复了小部件未显示在小部件列表中的错误,因为我修复了清单中的拼写错误^^
      猜你喜欢
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 2016-02-24
      • 2013-07-02
      • 1970-01-01
      相关资源
      最近更新 更多