android.content.ActivityNotFoundException但在Manifest中声明

时间:2017-06-12 06:18:48

标签: android android-activity android-manifest

我的清单文件中有以下内容:

 <activity
            android:name="org.sipdroid.codecs.Codecs$CodecSettings"
            android:label="@string/app_name" >
 </activity>

这是班级:

public static class CodecSettings extends PreferenceActivity {

    private static final int MENU_UP = 0;
    private static final int MENU_DOWN = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.codec_settings);

        // for long-press gesture on a profile preference
        registerForContextMenu(getListView());

        addPreferences(getPreferenceScreen());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);

        menu.setHeaderTitle(R.string.codecs_move);
        menu.add(Menu.NONE, MENU_UP, 0,
             R.string.codecs_move_up);
        menu.add(Menu.NONE, MENU_DOWN, 0,
             R.string.codecs_move_down);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

        int posn = (int)((AdapterContextMenuInfo)item.getMenuInfo()).position;
        Codec c = codecs.elementAt(posn);
        if (item.getItemId() == MENU_UP) {
            if (posn == 0)
                return super.onContextItemSelected(item);
            Codec tmp = codecs.elementAt(posn - 1);
            codecs.set(posn - 1, c);
            codecs.set(posn, tmp);
        } else if (item.getItemId() == MENU_DOWN) {
            if (posn == codecs.size() - 1)
                return super.onContextItemSelected(item);
            Codec tmp = codecs.elementAt(posn + 1);
            codecs.set(posn + 1, c);
            codecs.set(posn, tmp);
        }
        PreferenceScreen ps = getPreferenceScreen();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
        String v = "";
        SharedPreferences.Editor e = sp.edit();

        for (Codec d : codecs)
            v = v + d.number() + " ";
        e.putString(Settings.PREF_CODECS, v);
        e.commit();
        ps.removeAll();
        addPreferences(ps);
        return super.onContextItemSelected(item);
    }

    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference p) {
        ListPreference l = (ListPreference) p;
        for (Codec c : codecs)
            if (c.key().equals(l.getKey())) {
                c.init();
                if (!c.isLoaded()) {
                    l.setValue("never");
                    c.fail();
                    l.setEnabled(false);
                    l.setSummary(l.getEntry());
                    if (l.getDialog() != null)
                        l.getDialog().dismiss();
                }
            }
        return super.onPreferenceTreeClick(ps,p);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterForContextMenu(getListView());
    }
}

我得到了:     无法找到显式活动类{org.sipdroid.sipua / org.sipdroid.codecs.Codecs $ CodecSettings};你有没有在AndroidManifest.xml中声明这个活动?

出了什么问题?

1 个答案:

答案 0 :(得分:-1)

1 活动不应该是静态类。

2 活动不应该是内部类。

当涉及到您的问题时,它会显示您声明了包名称两次。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourpackage.activities">

    <application
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity"> 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

如果您在<manifest ../>中声明了包名称,则无需在<activity android:name=".MainActivity">中再次声明它。只需使用“。”而不是那个。