Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,376 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to setup a preference sceen with AndroidX.Preference.
But i'm getting this error when opening the fragment containing the preference:
Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setAdapter(androidx.recyclerview.widget.RecyclerView$Adapter)' on a null object reference'
PreferenceFragment:
using Android.OS;
using Android.Views;
using AndroidX.Preference;
namespace GeoTrack.Android
{
public class PreferenceServerauthFragment : PreferenceFragmentCompat
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
return inflater.Inflate(Resource.Layout.preference_serverauth_fragment, container, false);
//return base.OnCreateView(inflater, container, savedInstanceState);
}
public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey)
{
SetPreferencesFromResource(Resource.Xml.preference_serverauth, rootKey);
}
}
}
The rootkey is null.
Resource\xml\preference.xml:
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
app:key="notifications"
app:title="Enable message notifications"/>
</PreferenceScreen>
Needed to delete the old:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
return inflater.Inflate(Resource.Layout.preference_serverauth_fragment, container, false);
//return base.OnCreateView(inflater, container, savedInstanceState);
}