title: Android Applications: Preference Activity Crashing
body: <p>I'm trying to set up a preference activity to edit some of my app settings (obviously) but it keeps crashing when I press the action bar button.</p>
  
  <p>Here is the run output:</p>
  
  <pre><code>11-24 19:40:18.629: E/AndroidRuntime(13755): FATAL EXCEPTION: main
  11-24 19:40:18.629: E/AndroidRuntime(13755): Process: com.andrewq.simplestflashlight, PID: 13755
  11-24 19:40:18.629: E/AndroidRuntime(13755): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andrewq.simplestflashlight/com.andrewq.simplestflashlight.Preferences}: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread.access$700(ActivityThread.java:135)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.os.Handler.dispatchMessage(Handler.java:102)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.os.Looper.loop(Looper.java:137)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread.main(ActivityThread.java:4998)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at java.lang.reflect.Method.invoke(Native Method)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
  11-24 19:40:18.629: E/AndroidRuntime(13755): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.Activity.setContentView(Activity.java:1928)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at com.andrewq.simplestflashlight.Preferences.onCreate(Preferences.java:16)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.Activity.performCreate(Activity.java:5243)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    ... 9 more
  11-24 19:40:18.629: E/AndroidRuntime(13755): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.PreferenceScreen" on path: DexPathList[[zip file "/data/app/com.andrewq.simplestflashlight-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.andrewq.simplestflashlight-1, /vendor/lib, /system/lib]]
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.createView(LayoutInflater.java:559)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
  11-24 19:40:18.629: E/AndroidRuntime(13755):    ... 18 more
  11-24 19:40:18.629: E/AndroidRuntime(13755):    Suppressed: java.lang.ClassNotFoundException: android.view.PreferenceScreen
  11-24 19:40:18.629: E/AndroidRuntime(13755):        at java.lang.Class.classForName(Native Method)
  11-24 19:40:18.629: E/AndroidRuntime(13755):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
  11-24 19:40:18.629: E/AndroidRuntime(13755):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
  11-24 19:40:18.629: E/AndroidRuntime(13755):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
  11-24 19:40:18.629: E/AndroidRuntime(13755):        ... 24 more
  11-24 19:40:18.629: E/AndroidRuntime(13755):    Caused by: java.lang.NoClassDefFoundError: Class "Landroid/view/PreferenceScreen;" not found
  11-24 19:40:18.629: E/AndroidRuntime(13755):        ... 28 more
  </code></pre>
  
  <p>Here is the class for the activity:</p>
  
  <pre><code>//Class name omitted but added in actual code
  //Imports omitted but added in actual code
  public class Preferences extends PreferenceActivity{
  
          @Override
          public void onCreate (Bundle savedInstanceState)
          {
              super.onCreate(savedInstanceState);
              setContentView(R.xml.preferences);
  
              //Initialize the "up" button
              getActionBar().setDisplayHomeAsUpEnabled(true);
          }
  
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              switch (item.getItemId()) {
              // Respond to the action bar's Up/Home button
              case android.R.id.home:
                  Intent upIntent = NavUtils.getParentActivityIntent(this);
                  if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                      // This activity is NOT part of this app's task, so create a new task
                      // when navigating up, with a synthesized back stack.
                      TaskStackBuilder.create(this)
                              // Add all of this activity's parents to the back stack
                              .addNextIntentWithParentStack(upIntent)
                              // Navigate up to the closest parent
                              .startActivities();
                  } else {
                      // This activity is part of this app's task, so simply
                      // navigate up to the logical parent activity.
                      NavUtils.navigateUpTo(this, upIntent);
                  }
              }
              return super.onOptionsItemSelected(item);
          }
  </code></pre>
  
  <p>Here's the layout file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;PreferenceCategory android:title="Application Settings" android:padding="10dp" &gt;
  
          &lt;CheckBoxPreference android:title="Check me!" 
              android:summary="This is a sample check box preference." 
              android:key="prefCheck" /&gt; 
  
      &lt;/PreferenceCategory&gt;
  
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>And FINALLY here's the menu file:</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;item
          android:id="@+id/action_about"
          android:icon="@drawable/action_about"
          android:showAsAction="always"
          android:title="@string/action_about"/&gt;
  
      &lt;item
          android:id="@+id/action_settings"
          android:showAsAction="never"
          android:title="@string/action_settings"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>Sorry if there's a not of unneeded code but I don't know what to omit in order to get a solution to my problem. Thanks in advance if anyone helps :)</p>
  
  <p>Andrew</p>