我没有任何可见的原因得到ActivityNotFoundException。我是Android的新手,所以我需要帮助。
我创建了菜单并从onOptionsItemSelected:
运行活动@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Settings.class));
return true;
}
return false;
}
设置类:
public class Settings extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/settings"
android:title="@string/action_settings"/>
</menu>
settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory>
<ListPreference
android:title="@string/menu_language_settings"
android:key="languagePreferences"
android:entries="@array/langPreferencesArray"
android:entryValues="@array/langPreferencesValues" />
<Preference
android:title="@string/menu_help"
android:key="helpPreferences" />
</PreferenceCategory>
</PreferenceScreen>
当然,我在清单中添加了活动声明:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.symbolrecogniser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.symbolrecogniser.StartAppActivity"
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="com.example.symbolrecogniser.Settings"
android:label="@string/settings_title">
</activity>
</application>
&GT;
有人有什么想法吗?
这是logCat:
05-13 01:07:44.169: E/AndroidRuntime(23122): FATAL EXCEPTION: main
05-13 01:07:44.169: E/AndroidRuntime(23122): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.symbolrecogniser/android.provider.Settings}; have you declared this activity in your AndroidManifest.xml?
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.Activity.startActivityForResult(Activity.java:2827)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.Activity.startActivity(Activity.java:2933)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.example.symbolrecogniser.StartAppActivity.onOptionsItemSelected(StartAppActivity.java:34)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.Activity.onMenuItemSelected(Activity.java:2205)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:756)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.view.View$PerformClick.run(View.java:9080)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.os.Handler.handleCallback(Handler.java:587)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.os.Looper.loop(Looper.java:123)
05-13 01:07:44.169: E/AndroidRuntime(23122): at android.app.ActivityThread.main(ActivityThread.java:3729)
05-13 01:07:44.169: E/AndroidRuntime(23122): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 01:07:44.169: E/AndroidRuntime(23122): at java.lang.reflect.Method.invoke(Method.java:507)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
05-13 01:07:44.169: E/AndroidRuntime(23122): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
05-13 01:07:44.169: E/AndroidRuntime(23122): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
您确定在&lt; manifest&gt;的“package”属性中声明的包吗?标签与Settings类所在的位置相同(不是子包)?
如果没有,您必须使用全名声明活动类,包括清单中“android:name”属性中的包。
答案 1 :(得分:1)
检查第一个代码段所在文件的“import”语句。某处可能有
import android.provider.Settings;
导入错误的设置类。