RecyclerView exception using PreferenceFragmentCompat without using RecyclerView
I am using PreferenceFragmentCompat and I am getting this runtime exception:
Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setAdapter(android.support.v7.widget.RecyclerView$Adapter)' on a null object reference
The confusing part is that my preference definition does not contain any RecyclerView. Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" >
<android.support.v7.preference.PreferenceCategory
android:layout="@layout/preference_first_category"
android:title="@string/pref_category_general">
<android.support.v7.preference.SwitchPreferenceCompat
android:title="@string/pref_demo_mode"
android:key="@string/pref_demo_mode_key"
android:defaultValue="true"
android:persistent="true" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:layout="@layout/preference_category"
android:key="serverCategory"
android:persistent="false"
android:title="@string/pref_category_server">
<android.support.v7.preference.EditTextPreference
android:title="@string/pref_server_control_ip"
android:summary="@string/pref_enter_ip_address"
android:defaultValue="@string/pref_enter_ip_address"
android:key="@string/pref_ctrl_ip_key"
android:selectAllOnFocus="true"
android:singleLine="true"
android:persistent="true" />
<android.support.v7.preference.EditTextPreference
android:title="@string/pref_server_admin_ip"
android:summary="@string/pref_enter_ip_address"
android:defaultValue="@string/pref_enter_ip_address"
android:key="@string/pref_admin_ip_key"
android:selectAllOnFocus="true"
android:singleLine="true"
android:persistent="true" />
<android.support.v7.preference.EditTextPreference
android:title="@string/pref_server_network_mask"
android:defaultValue="@string/pref_enter_network_mask"
android:summary="@string/pref_enter_network_mask"
android:key="@string/pref_network_mask_key"
android:selectAllOnFocus="true"
android:singleLine="true"
android:persistent="true" />
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>
I've looked at the API reference and can clearly see that the PreferenceFragmentCompat supports RecyclerView, but I've seen some working code examples that don't have a RecyclerView in my preference, so it looks like the RecyclerView is optional.
Do I need to override any RecyclerView methods? Other working examples without RecyclerView didn't need this, so I don't understand how to resolve this.
Thanks, -Andres
+3
source to share
No one has answered this question yet
Check out similar questions: