4

我让我的应用程序做它的应用程序的事情(保存记录、处理单例等等),并且我有一个嵌套服务来处理套接字连接。我以前在它自己的类中拥有该服务,但随着我提高它的效率,我认为将它移动到应用程序中是个好主意。我更新了清单:

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

我认为这是声明嵌套服务的正确方法,但我得到了一个 InstantiationException。服务是否需要是静态的,或者我根本不允许将服务嵌套到另一个类中?

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/AndroidRuntime(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
4

1 回答 1

5

您必须有一个默认构造函数。所以是的,将其声明为静态或将其放入它自己的类中。

于 2011-04-15T20:10:17.110 回答