user1628978
user1628978

Reputation: 501

No launcher activity found! Can't get widget to work

I've created an app widget that has the following classes and xml files: AFBWidget.java

WidgetConfig.java (Configuration screen for users to input something into a textfield that shows up in the widget layout)

widget.xml (the layout of the actual widget)

widgetconfig.xml (same as widgetconfig.java ((except it is the actual layout)))

widget_stuff.xml (the android appwidget provider)

Here is my Manifest:

<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>

Originally, I didn't have the .widget activity in there and I didn't have the

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

either, so I got the error "No laucher activity found!". So to fix that, I added the launcher to my appwidget config and it fixed the error but then the widget would stop working and force close on the emulator.

My issue is that I don't know what activity to put the launcher on to make the widget work without crashing.

New Errors:

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)

Upvotes: 6

Views: 3525

Answers (2)

user1628978
user1628978

Reputation: 501

I FINALLY FIXED IT AFTER 3 DAYS! Ok, so it was indeed because my two java classes were in a default package. So to fix that, since my classes were being accessed via a different package, I created a new package that was my app (com.example.awesomefilebuilderwidget) and then moved the classes into there and now it works with no problemos! :DD Thanks for all you've done I really do apperciate it! – user1628978

Upvotes: 1

Filip Zymek
Filip Zymek

Reputation: 2646

If you want to create widget only without any, lets call it, "main" activity, there is no need to declare intent and category filters for your configuration activity. You only need to specify intent filter for action android.appwidget.action.APPWIDGET_CONFIGURE. This activity will be lauched when user adds widget to home screen. You also need to declate this activity inside your appwidget-provider xml file with following attribute android:configure.

So in your case manifest should look something like this:

<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>

And in your 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>

Upvotes: 0

Related Questions