开发者

Is a service allowed to be nested into an application?

I have my application doing its application things (keeping records, handling singletons, etc...), and I have a nested service that will handle socket connections. I previously had the service in it's own class, but as I made it more efficient, I thought is a good idea to move it into the application. I updated the manifest:

<service android:name="com.arm.core.ArmApplication$IOService"/> 

I thought this was the proper method of declaring a nested service, but I get an InstantiationException. Does the service need to be static or am I not allowed to have a service be nested into another class at all?

04-15 14:11:53.167: ERROR/AndroidRuntime(18379): FATAL EXCEPTION: main
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): java.lang.RuntimeException: Unable to instantiate service com.android.appion.arm.core.AppionApplication$IOService: java.lang.InstantiationException: com.android.appion.arm.core.AppionApplication$IOService
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:3102)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.app.ActivityThread.access$3300(ActivityThread.java:135)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2202)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.os.Looper.loop(Looper.java:144)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.app.ActivityThread.main(ActivityThread.java:4937)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at dalvik.system.NativeStart.main(Native Method)
04-15 14:11:53.167: ERROR/A开发者_如何学运维ndroidRuntime(18379): Caused by: java.lang.InstantiationException: com.android.appion.arm.core.AppionApplication$IOService
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at java.lang.Class.newInstanceImpl(Native Method)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at java.lang.Class.newInstance(Class.java:1429)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:3099)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379):     ... 10 more


You must have a default constructor. So yes, declare it as static or put it in it's own class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜