2

当我想向首选项屏幕启动意图时,我遇到了强制关闭。即使在清单中声明它之后,我仍然遇到这个问题。

显现

<activity android:name=".Preferences" ></activity>

从 MainActivity 启动意图

Intent startPreference = new Intent(MainActivity.this,Preferences.class);
startActivity(startPreference);

首选项屏幕

public class Preferences extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);   
    }
}

然而,每当我打开意图时,我遇到了

10-04 14:02:45.088: E/AndroidRuntime(11201): android.content.ActivityNotFoundException: Unable to find explicit activity class {dev.example.activity/java.util.prefs.Preferences}; have you declared this activity in your AndroidManifest.xml?

编辑:完整清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dev.example.activity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="Example"
        android:theme="@android:style/Theme.Light.NoTitleBar" >
        <activity
            android:name=".MainActivity"
            android:label="Example" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Individual"
            android:label="Example" >
        </activity>
        <activity android:name="dev.example.activity.Preferences" >
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

完整的日志猫

10-04 14:24:35.408: E/AndroidRuntime(12936): FATAL EXCEPTION: main
10-04 14:24:35.408: E/AndroidRuntime(12936): android.content.ActivityNotFoundException: Unable to find explicit activity class {dev.example.activity/java.util.prefs.Preferences}; have you declared this activity in your AndroidManifest.xml?
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.Activity.startActivityForResult(Activity.java:2827)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.Activity.startActivity(Activity.java:2933)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at dev.shaunidiot.mycolorscreen.MainActivity.onOptionsItemSelected(MainActivity.java:166)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.Activity.onMenuItemSelected(Activity.java:2205)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:768)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:147)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.view.View$PerformClick.run(View.java:9229)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.os.Handler.handleCallback(Handler.java:587)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.os.Looper.loop(Looper.java:130)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at android.app.ActivityThread.main(ActivityThread.java:3701)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at java.lang.reflect.Method.invokeNative(Native Method)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at java.lang.reflect.Method.invoke(Method.java:507)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
10-04 14:24:35.408: E/AndroidRuntime(12936):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1

您指向java.util.prefs.Preferences:那不是您的活动。以这种方式创建意图:

Intent startPreference = new Intent(MainActivity.this,             
                           dev.example.activity.Preferences.class);
startActivity(startPreference);
于 2012-10-04T06:16:13.607 回答
0

请声明您的活动全名

com.packagename.classname

我认为它解决了你的错误。

编辑:-

您的活动扩展 了我忘记看到的PreferenceActivity,以便声明您的活动,如下所示。

<activity android:name=".Preferences" android:label="@string/prefTitle"
    android:screenOrientation="nosensor">
    <intent-filer>
        <action android:name=".Preferences" />
        <category android:name="android.intent.cetagory.PREFERENCE" />
    </intent-filer>

于 2012-10-04T06:09:16.053 回答
0

只需将此行添加到清单

 <activity
    android:name=".Preferences"
    android:label="@string/set_preferences">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT"/>

    </intent-filter>  
</activity>

仍然,如果您遇到错误。点击这里

于 2012-10-04T06:14:53.593 回答