问题描述
08-01 16:32:15.072: ERROR/AndroidRuntime(353): FATAL EXCEPTION: main08-01 16:32:15.072: ERROR/AndroidRuntime(353): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.manning.android/com.manning.android.Activity03}: java.lang.IllegalStateException: System services not available to Activities before onCreate()08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread.access$2300(ActivityThread.java:125)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.os.Handler.dispatchMessage(Handler.java:99)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.os.Looper.loop(Looper.java:123)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread.main(ActivityThread.java:4627)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at java.lang.reflect.Method.invokeNative(Native Method)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at java.lang.reflect.Method.invoke(Method.java:521)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at dalvik.system.NativeStart.main(Native Method)08-01 16:32:15.072: ERROR/AndroidRuntime(353): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.Activity.getSystemService(Activity.java:3526)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at com.manning.android.Activity03.<init>(Activity03.java:16)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at java.lang.Class.newInstanceImpl(Native Method)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at java.lang.Class.newInstance(Class.java:1429)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)08-01 16:32:15.072: ERROR/AndroidRuntime(353): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)08-01 16:32:15.072: ERROR/AndroidRuntime(353): ... 11 more
解决方案
System services not available to Activities before onCreate() 写的很明白,在你的Activity03中,需要在onCreate()中调用了 super.onCreate()方法之后再绑定Service。
解决方案二:
SDK的模拟器没装好吧