Starting to learn about creating the settings page, but my app crashes when I select 'settings' from the action bar, and I get this error in logcat:

Caused by: java.lang.ClassCastException: com.myexamlpe.thing.Preference cannot be cast to android.app.Activity

Here's how I call it from my main class:

public class RCs extends FragmentActivity implements
    rcfrequency.ToolbarListener, RCButtons.ToolbarListener {
.
.
.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:

        Intent myIntent = new Intent(this, Preference.class);
        startActivity(myIntent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }

}

Here's my Preference class:

public class Preference extends PreferenceFragment implements OnSharedPreferenceChangeListener  {

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

Related posts

Recent Viewed