Josh
Josh

Reputation: 16532

PreferenceActivity causes Force close

I have a bit of an issue that I am not sure how to fix. I have an options menu which has code like this

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.main_menu_settings:
        startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

No error happens if I comment out the line

startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));

My preferences activity looks like this

public class BackofficePreferencesActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.layout.preferences);
    }
}

and my layout

<PreferenceCategory android:title="System Configuration">
    <ListPreference
       android:title="Environment"
       android:summary="Select the environment"
       android:key="@string/pref_current_environment"
       android:defaultValue="Production"
       android:entries="@array/environment_list"
       android:entryValues="@array/environment_list"
       android:dialogTitle="Select Environment" />
</PreferenceCategory>

I even tried removing the list preference to see if the screen would load empty, but it still errors. In eclipse, usually I can see what went wrong by looking in the LogCat tab, but for some reason nothing is being logged there anymore. I tried rebooting my AVD and that hasn't helped.

Upvotes: 0

Views: 570

Answers (1)

Wroclai
Wroclai

Reputation: 26925

You need to declare the Activty in your manifest file.

Sample XML code:

<activity android:label="@string/sample"
        android:name=".Sample"
        android:icon="@drawable/sample">
</activity>

Upvotes: 1

Related Questions