Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Android:problems creating settings menu

Options
  • 10-07-2013 10:59pm
    #1
    Closed Accounts Posts: 1,235 ✭✭✭


    Hi,
    I keep getting a force close every time I click on settings in the action bar> ive been looking at stack overflow+the android dev website and have confused myself into a hole :)
    Here's the code for onOptionsItemSelected().Creating the intent causes the force close.
    public boolean onOptionsItemSelected(MenuItem item) {
    	    // Handle item selection
    	    switch (item.getItemId()) {
    	        case R.id.action_settings:
    	           // this code causes force close when settings is touched in actionbar
    	        	Intent settingsIntent = new Intent(this, Preferences.class);
    	            this.startActivity(settingsIntent);
    	            return true;
    	        case R.id.action_about:
    	            showAbout();
    	            return true;
    	        default:
    	            return super.onOptionsItemSelected(item);
    	    }
    	}
    

    And here,s the code for the Preferences class
    public class Preferences extends PreferenceActivity {
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
            addPreferencesFromResource(R.xml.preferences);
        }
        
    }
    

    and heres the preferences.xml
    <?xml version="1.0" encoding="utf-8"?>
    
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
            <PreferenceCategory
                    android:title="Blinds">
                     <EditTextPreference
                    android:name="SmallBlindsEditText Preference"
                    android:summary="This allows you to change small blind amount"
                    android:defaultValue="Nothing"
                    android:title="Small Blind"
                    android:key="SmallBlindTextPref" />
                     
                     <RingtonePreference
                    android:name="Multiplier Preference"
                    android:summary="Change blind multiplier"
                    android:title="Multiplier"
                    android:key="multiplierPref" /> 
                    
            </PreferenceCategory>
            
    </PreferenceScreen>
    

    Now from looking at the android dev notes(and eclipse points out)that addPreferencesFromResource(R.xml.preferences) has been deprecated and that I should use PreferenceFragments but when I follow the examples I get a message saying they are for api 11 (and not 8 which my app is aimed at)

    Like I said I'm not sure where i'm goin wrong,any help much appreciated


Comments

  • Closed Accounts Posts: 1,235 ✭✭✭returnNull


    I seemed to have got it sorted just by removing the 2nd option in my preferences,xml and cleaned and rebuilt the project


  • Registered Users Posts: 2,345 ✭✭✭Kavrocks


    In future you should paste the LogCat output too. It'll tell somebody what has gone wrong and generally where so they can help you easier and quicker.


Advertisement