初学Android几天,遇到奇怪的错误,求解。
//----------- 报错如下 ------------
11-15 07:31:26.325: D/AndroidRuntime(817): Shutting down VM
11-15 07:31:26.325: W/dalvikvm(817): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-15 07:31:26.335: E/AndroidRuntime(817): FATAL EXCEPTION: main
11-15 07:31:26.335: E/AndroidRuntime(817): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xxxx.android/com.xxxx.android.service.BindService}; have you declared this activity in your AndroidManifest.xml?
11-15 07:31:26.335: E/AndroidRuntime(817): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.app.Activity.startActivityForResult(Activity.java:2817)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.app.Activity.startActivity(Activity.java:2923)
11-15 07:31:26.335: E/AndroidRuntime(817): at com.xxxx.android.MainActivity$1.onClick(MainActivity.java:28)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.view.View.performClick(View.java:2408)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.view.View$PerformClick.run(View.java:8816)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.os.Handler.handleCallback(Handler.java:587)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.os.Handler.dispatchMessage(Handler.java:92)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.os.Looper.loop(Looper.java:123)
11-15 07:31:26.335: E/AndroidRuntime(817): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-15 07:31:26.335: E/AndroidRuntime(817): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 07:31:26.335: E/AndroidRuntime(817): at java.lang.reflect.Method.invoke(Method.java:521)
11-15 07:31:26.335: E/AndroidRuntime(817): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-15 07:31:26.335: E/AndroidRuntime(817): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-15 07:31:26.335: E/AndroidRuntime(817): at dalvik.system.NativeStart.main(Native Method)
//------------- AndroidManifest.xml里面有如下声明 --------------
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.xxxx.android.service.SecondService" />
<service android:name="com.xxxx.android.service.BindService" />
</application>
Unable to find explicit activity class 你这的确是没有要找的Activity,只有一个Service名字是com.xxxx.android.service.BindServic。这startActivity用错了
com.xxxx.android/com.xxxx.android.service.BindService
而且很明显这里com.xxxx.android这一段路径重复了。
是按钮的OnClickListener()函数里,把startService()函数写成了startActivity()。