title: RunTimeException in PreferenceFragment
body: <p>I am following <a href="https://www.udacity.com/course/viewer#!/c-ud853/l-1474559101/e-1643578589/m-1643578588" rel="nofollow">this tutorial</a>. In that the PreferenceActivity is used to create Settings. However it was mentioned that I can use Fragments if I like, so I went ahead and used PreferenceFrament in a normal activity. But when I ran the app, it crashed giving the following log - </p>
  
  <pre><code>07-25 10:41:02.048    7515-7515/com.example.sunshine E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sunshine/com.example.sunshine.SettingsActivity}: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2063)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
              at android.app.ActivityThread.access$600(ActivityThread.java:134)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4744)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
              at android.preference.PreferenceFragment.ensureList(PreferenceFragment.java:350)
              at android.preference.PreferenceFragment.getListView(PreferenceFragment.java:336)
              at android.preference.PreferenceFragment.bindPreferences(PreferenceFragment.java:330)
              at android.preference.PreferenceFragment.onActivityCreated(PreferenceFragment.java:171)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:852)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1039)
              at android.app.BackStackRecord.run(BackStackRecord.java:635)
              at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1411)
              at android.app.Activity.performStart(Activity.java:5017)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2036)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
              at android.app.ActivityThread.access$600(ActivityThread.java:134)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4744)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>When I searched on SO, I came to know the crash is somewhat related to ListFragment. But I am sure I did not use it in my app. PreferenceFragment might have called it though. I cannot pinpoint the problem here. Can you help me to solve it?</p>
  
  <p>Here's the preference xml I am using - </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      &gt;
      &lt;EditTextPreference
          android:title="@string/pref_location_label"
          android:key="@string/pref_location_key"
          android:defaultValue="@string/pref_location_default"
          android:inputType="text"
          android:singleLine="true"
          /&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>And here's the SettingsActivity, along with Fragment - </p>
  
  <pre><code>public class SettingsActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_settings);
          if (savedInstanceState == null) {
              getFragmentManager().beginTransaction()
                      .add(R.id.container, new SettingsFragment())
                      .commit();
          }
      }
  
      public static class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
  
          public SettingsFragment() {
          }
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              // Add 'general' preferences, defined in the XML file
              addPreferencesFromResource(R.xml.pref_general);
  
              // For all preferences, attach an OnPreferenceChangeListener so the UI summary can be
              // updated when the preference changes.
              bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_key)));
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
              return rootView;
          }
  
          /**
           * Attaches a listener so the summary is always updated with the preference value.
           * Also fires the listener once, to initialize the summary (so it shows up before the value
           * is changed.)
           */
          private void bindPreferenceSummaryToValue(Preference preference) {
              // Set the listener to watch for value changes.
              preference.setOnPreferenceChangeListener(this);
  
              // Trigger the listener immediately with the preference's
              // current value.
              onPreferenceChange(preference,
                      PreferenceManager
                              .getDefaultSharedPreferences(preference.getContext())
                              .getString(preference.getKey(), ""));
          }
  
          @Override
          public boolean onPreferenceChange(Preference preference, Object value) {
              String stringValue = value.toString();
  
              if (preference instanceof ListPreference) {
                  // For list preferences, look up the correct display value in
                  // the preference's 'entries' list (since they have separate labels/values).
                  ListPreference listPreference = (ListPreference) preference;
                  int prefIndex = listPreference.findIndexOfValue(stringValue);
                  if (prefIndex &gt;= 0) {
                      preference.setSummary(listPreference.getEntries()[prefIndex]);
                  }
              } else {
                  // For other preferences, set the summary to the value's simple string representation.
                  preference.setSummary(stringValue);
              }
              return true;
          }
      }
  }
  </code></pre>
  
  <p>Is there anything else I need to change to make it work for Fragments instead of Activity?</p>