N
N
nohchiadam2019-06-13 12:32:23
Java
nohchiadam, 2019-06-13 12:32:23

How to get getDefaultSharedPreferences in Adapter?

Can't get instance of "getDefaultSharedPreferences" settings in Adapter.

@Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {


        mPreference = PreferenceManager.getDefaultSharedPreferences(context);

        mPreference.registerOnSharedPreferenceChangeListener(this);

Throws java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
Am I trying to get this instance in the wrong place?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2019-06-13
@nohchiadam

Like context == null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question