2 qq 24684521 qq_24684521 于 2015.06.18 10:56 提问

Android Service初学者跪求大神指点

06-18 10:25:51.857: E/AndroidRuntime(21341): FATAL EXCEPTION: main
06-18 10:25:51.857: E/AndroidRuntime(21341): Process: com.hsnc.music, PID: 21341
06-18 10:25:51.857: E/AndroidRuntime(21341): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hsnc.music/com.hsnc.music.MusicService}: java.lang.ClassCastException: com.hsnc.music.MusicService cannot be cast to android.app.Activity
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2189)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread.access$800(ActivityThread.java:147)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1226)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.os.Handler.dispatchMessage(Handler.java:102)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.os.Looper.loop(Looper.java:136)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread.main(ActivityThread.java:5137)
06-18 10:25:51.857: E/AndroidRuntime(21341): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 10:25:51.857: E/AndroidRuntime(21341): at java.lang.reflect.Method.invoke(Method.java:515)
06-18 10:25:51.857: E/AndroidRuntime(21341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
06-18 10:25:51.857: E/AndroidRuntime(21341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:617)
06-18 10:25:51.857: E/AndroidRuntime(21341): at dalvik.system.NativeStart.main(Native Method)
求大神指点 点击运行时 程序立马死掉 问题出现在哪了呢????

E/AndroidRuntime(21341): Caused by: java.lang.ClassCastException: com.hsnc.music.MusicService cannot be cast to android.app.Activity
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
06-18 10:25:51.857: E/AndroidRuntime(21341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-18 10:25:51.857: E/AndroidRuntime(21341): ... 11 more

2个回答

bdmh
bdmh   Ds   Rxr 2015.06.18 10:58

com.hsnc.music.MusicService cannot be cast to android.app.Activity
你代码有问题,你非要把service转换成activity,肯定不行啊,

qq_24684521
qq_24684521 谢谢
2 年多之前 回复
beacon_2011
beacon_2011   Rxr 2015.06.19 13:32
Csdn user default icon
上传中...
上传图片
插入图片