Priyanka
Priyanka

Reputation: 207

class cast exception error

Trying to run a live wallpaper project with two classes: 1. LiveWallpaper 2. LiveWallpaperSettings I added both names in manifest but I don't know why I am getting this classcast exception here. I am adding manifest code as well:

 12-13 22:41:48.861: W/dalvikvm(3599): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
    12-13 22:41:48.871: E/AndroidRuntime(3599): FATAL EXCEPTION: main
    12-13 22:41:48.871: E/AndroidRuntime(3599): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ca.jvsh.livewallpaper/ca.jvsh.livewallpaper.LiveWallpaper}: java.lang.ClassCastException: ca.jvsh.livewallpaper.LiveWallpaper cannot be cast to android.app.Activity
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.os.Handler.dispatchMessage(Handler.java:99)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.os.Looper.loop(Looper.java:137)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread.main(ActivityThread.java:4340)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invokeNative(Native Method)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invoke(Method.java:511)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at dalvik.system.NativeStart.main(Native Method)
    12-13 22:41:48.871: E/AndroidRuntime(3599): Caused by: java.lang.ClassCastException: ca.jvsh.livewallpaper.LiveWallpaper cannot be cast to android.app.Activity
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
    12-13 22:41:48.871: E/AndroidRuntime(3599):     ... 11 more
    12-13 22:41:51.891: I/Process(3599): Sending signal. PID: 3599 SIG: 9

*Manifest code*

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ca.jvsh.livewallpaper"
    android:versionCode="1"
    android:versionName="1.0.20100908.1" >
        <uses-sdk android:minSdkVersion="7" />
        <uses-feature android:name="android.software.live_wallpaper" />
        <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_WALLPAPER" >
        <service
            android:name=".LiveWallpaper"
            android:icon="@drawable/icon"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
                <meta-data
                android:name="android.service.wallpaper"
                android:resource="@layout/livewallpaper" />
        </service>
        <activity
            android:name=".LiveWallpaperSettings"
            android:exported="true"
            android:icon="@drawable/icon"
            android:label="@string/livewallpaper_settings"
            android:theme="@android:style/Theme.Light.WallpaperSettings" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />  
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Upvotes: 0

Views: 223

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

you are declaring Service and Activity in manifest with same name so use different name for each see

<service
            android:name=".LiveWallpaper"  <<<-----here
            android:icon="@drawable/icon"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name=
                  "android.service.wallpaper.WallpaperService" />
            </intent-filter>

            <meta-data
                android:name="android.service.wallpaper"
                android:resource="@layout/livewallpaper" />
        </service>

        <activity
            android:name=".LiveWallpaper"   <<<-----here
            android:exported="true"
            android:icon="@drawable/icon"
            android:label="@string/livewallpaper_settings"

and in code part if your are starting LiveWallpaper service from then start it as LiveWallpaperSettings :

Intent intent=new Intent(getApplicationContext(),LiveWallpaper.class);
startService(intent);

Upvotes: 3

Related Questions