Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:29:09+00:00 2026-06-17T12:29:09+00:00

I’m currently trying to make a settings menu, that will show a MultiSelectListPreference ,

  • 0

I’m currently trying to make a settings menu, that will show a MultiSelectListPreference, to select multiple contacts from your contact list.

At this moment, I’m receiving an NullPointerException, when i try to MultiSelectListPreference#setEntryValue(CharSequence[]) If I put the setEntries first, that one throws the same exception.

I’ve put a breakpoint, to see step by step what happens. The variables are filled because they store Strings, they can contain a String “null”, so I guess that it doesn’t fail if there is no Display_Name available or so.

I based the findPreference on the example of this answer

Anyone has an idea? If you need more information, tell me. Thanks for reading!

package be.wdk.sendtowork;contactNumberArray

import android.database.Cursor;
import android.os.Bundle;
import android.preference.MultiSelectListPreference;
import android.preference.PreferenceFragment;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.Toast;

public class PreferenceClass extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Integer countContacts = 0;

        String[] projection = new String[]{
                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER,
                ContactsContract.CommonDataKinds.Phone.PHOTO_URI
        };

        String selection = ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER;
        String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;
        try {
            Cursor c1 = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, selection, null, sortOrder);
            c1.moveToFirst();
            Integer c1columncount = c1.getColumnCount();
            Integer c1count = c1.getCount();
            Toast toastje = Toast.makeText(getActivity(), c1columncount.toString() + " - " + c1count.toString(), Toast.LENGTH_SHORT);
            toastje.show();

            CharSequence[] contactNameArray = new CharSequence[c1count], contactNumberArray = new CharSequence[c1count];
            MultiSelectListPreference mslp = (MultiSelectListPreference) findPreference("contactList");
            do {
                contactNameArray[countContacts] = c1.getString(0) + " - " + c1.getString(2);
                contactNumberArray[countContacts] = c1.getString(1);
                countContacts += 1;
            } while(c1.moveToNext());

            mslp.setEntryValues(contactNumberArray); //<- line that throws the error
            mslp.setEntries(contactNameArray);
            addPreferencesFromResource(R.xml.preferences);
        } 
        catch (Exception e) {
            Log.v("TAG", " " + e.toString());
            e.getMessage();
        }
    }
}

EDIT: Ok, I did a couple more checks.
-I made a test preference in my XML and used the findPrefence to make an object of it to work with -> returns NULL
-I have set my key of my MultiSelectListPreference to @string/test, putted this in my strings.xml, findpreference still returns Null.

Can there be a problem with my PreferenceFragment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:29:11+00:00Added an answer on June 17, 2026 at 12:29 pm

    Ok, i found what my problem was.

    MultiSelectListPreference mslp = (MultiSelectListPreference) findPreference("contactList"); 
    

    returns NULL because

    addPreferencesFromResource(R.xml.preferences);
    

    is not done at the start… so it didn’t load my preferences in yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.