在MainActivity类中,我有以下代码转到settings.class。
Intent intent1 = new Intent(MainActivity.this,Settings.class);
startActivity(intent1);
但我有例外。 logcat显示以下错误。
11-17 12:31:50.245: E/AndroidRuntime(11166): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.commlink.messaging/com.commlink.messaging.Settings}; have you declared this activity in your AndroidManifest.xml?
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1634)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Activity.startActivityForResult(Activity.java:3507)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Activity.startActivityForResult(Activity.java:3459)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Activity.startActivity(Activity.java:3710)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Activity.startActivity(Activity.java:3678)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.commlink.messaging.MainActivity.onOptionsItemSelected(MainActivity.java:105)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.Activity.onMenuItemSelected(Activity.java:2674)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1074)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:206)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.widget.AdapterView.performItemClick(AdapterView.java:299)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.widget.AbsListView.performItemClick(AbsListView.java:1152)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.widget.AbsListView$3.run(AbsListView.java:3865)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.os.Handler.handleCallback(Handler.java:808)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.os.Handler.dispatchMessage(Handler.java:103)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.os.Looper.loop(Looper.java:193)
11-17 12:31:50.245: E/AndroidRuntime(11166): at android.app.ActivityThread.main(ActivityThread.java:5330)
11-17 12:31:50.245: E/AndroidRuntime(11166): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 12:31:50.245: E/AndroidRuntime(11166): at java.lang.reflect.Method.invoke(Method.java:515)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
11-17 12:31:50.245: E/AndroidRuntime(11166): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
11-17 12:31:50.245: E/AndroidRuntime(11166): at dalvik.system.NativeStart.main(Native Method)
我在menifest.xml中对Settings.class进行了decalred。我的menifest.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commlink.messaging"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyAppTheme" >
<activity
android:name="com.commlink.messaging.MainActivity"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name="com.commlink.messaging.New_Message"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.commlink.messaging.Settings"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".SmsBroadcastReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver android:name=".MmsReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".ComposeSmsActivity"
android:theme="@style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<!-- Service that delivers messages from the phone "quick response" -->
<service android:name=".HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
</application>
</manifest>
我该怎么做才能解决此异常?
答案 0 :(得分:1)
像这样更改你的AndroidManifest.xml
。
改变你的android:这样的名字。因为您的包名已经在AndroidManifest.xml的顶部构建。
<activity
android:name=".Settings"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>