Fixing a nasty RuntimeException in Android Preferences

You may come across this exception if you are using PreferenceActivity/PreferenceFragment, and have been messing around with custom list separator styles.

The exception looks like this:

05-03 15:35:10.013    7029-7029/ W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0cb3b20)  
05-03 15:35:10.023    7029-7029/ E/AndroidRuntime﹕ FATAL EXCEPTION: main  
    Process:, PID: 7029
    java.lang.RuntimeException: Binary XML file line #18: You must supply a layout_width attribute.
            at android.content.res.TypedArray.getLayoutDimension(
            at android.view.ViewGroup$LayoutParams.setBaseAttributes(
            at android.view.ViewGroup$LayoutParams.<init>(
            at android.widget.AbsListView$LayoutParams.<init>(
            at android.widget.AbsListView.generateLayoutParams(
            at android.widget.AbsListView.generateLayoutParams(
            at android.view.LayoutInflater.inflate(
            at android.view.LayoutInflater.inflate(
            at android.preference.Preference.onCreateView(
            at android.preference.Preference.getView(


I got this error when switching my styles over to the new AppCompat v22.1 library, to get rid of old theme files and simplify my theme.

It is complaining about the custom listSeparatorTextViewStyle not having a specified layout_width. You can add that to your custom listSeparatorTextViewStyle:

<item name="android:layout_width">match_parent</item>  
<item name="android:layout_height">wrap_content</item>  

What fixed the error for me, was just removing my custom listSeparatorTextViewStyle in my theme file, as I didn't need it anymore.

comments powered by Disqus