I'm having a hard time here with AlphabetIndexer here. I'm trying to use it to produce sectioned listview:
private static final String sAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
private AlphabetIndexer mIndexer;
public ContactAlphabetizedAdapter(Context context, int layout,
Cursor cursor, String[] from, int[] to) {
super(context, layout, cursor, from, to);
mIndexer = new AlphabetIndexer(cursor, cursor.getColumnIndexOrThrow(ContactsContract.Data.DISPLAY_NAME), sAlphabet);
On my device I app crashes and the problem is:
E/AndroidRuntime(5188): Caused by: java.lang.NullPointerException
E/AndroidRuntime(5188): at android.widget.AlphabetIndexer.compare(AlphabetIndexer.java:128)
E/AndroidRuntime(5188): at android.widget.AlphabetIndexer.getSectionForPosition(AlphabetIndexer.java:265)
That’s something to AlphabetIndexer internals, how do I fix this?
You should probably post more of your code to confirm this, but I’m guessing you cursos has changed, or for some other reason cursor[columnIndex] returns null, by the time
getSectionForPositionis evaluated.According to this outstanding issue, this situation will trigger a very similar NPE to what you are experiencing
Again, the real problem is somewhere in the code that you didn’t post. The Alphabetindexer is just not handling that situation all too well.