我使用意图指向下一个活动,但是当我点击按钮时,我收到以下错误。
03-29 11:25:55.414: E/AndroidRuntime(3921): FATAL EXCEPTION: main
\
**03-29 11:25:55.414: E/AndroidRuntime(3921): android.content.ActivityNotFoundException:
Unable to find explicit activity class {mycube.test/mycube.test.Compte}; have you declared
this activity in your AndroidManifest.xml?**
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.app.Activity.startActivityForResult(Activity.java:2827)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.app.Activity.startActivity(Activity.java:2933)
03-29 11:25:55.414: E/AndroidRuntime(3921): at mycube.test.Menu.onClick(Menu.java:143)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.view.View.performClick(View.java:2538)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.view.View$PerformClick.run(View.java:9152)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.os.Handler.handleCallback(Handler.java:587)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.os.Handler.dispatchMessage(Handler.java:92)
03-29 11:25:55.414: E/AndroidRuntime(3921): at android.os.Looper.loop(Looper.java:130)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
android.app.ActivityThread.main(ActivityThread.java:3687)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
java.lang.reflect.Method.invokeNative(Native Method)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
java.lang.reflect.Method.invoke(Method.java:507)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-29 11:25:55.414: E/AndroidRuntime(3921): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-29 11:25:55.414: E/AndroidRuntime(3921): at dalvik.system.NativeStart.main(Native Method)
但是我的清单中存在该文件。我在清单中省略了一行吗?
这是我的清单文件。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mycube.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".Menu"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<activity android:name=".Compte" android:screenOrientation="portrait" />
</manifest>
答案 0 :(得分:15)
您已在应用标记之外声明此活动。
<activity android:name=".Compte" android:screenOrientation="portrait" />
像这样:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".Menu"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Compte"
android:screenOrientation="portrait" />
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
答案 1 :(得分:2)
您将它放在应该位于应用标记内的错误位置。
您的所有<activity... />
标记都应放在<application.. />
标记下。
它应该是这样的:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".Compte"
android:screenOrientation="portrait" />
<activity
android:name=".Menu"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 2 :(得分:0)
唯一要查找的异常如下所示。
android.content.ActivityNotFoundException:无法找到显式 活动课 {com.firstp.ta.myapplication / com.firstp.ta.myapplication.Activity1}; 您是否在AndroidManifest.xml中声明了此活动?
显然,您没有在AndroidManifest.xml文件中列出您的活动,或者如果列出了活动,则该活动不在必需的标记内。它还将完整的活动路径提到为{com.firstp.ta.myapplication / com.firstp.ta.myapplication.Activity1},其中Activity1是您的活动,需要在AndroidManifest.xml文件中提及。