2

I'm trying to make an app that will use an AutoCompleteTextView and read from your contacts depending on what you type, so it doesn't have to deal with a huge array. Unfortunately the ArrayAdapter doesn't seem to like me. Here is my code for it:

    private void updateAdapter(String[] nC)
{

    autoAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, nC);

    autoText.setAdapter(autoAdapter);
}

This throws this:

WARN/Filter(16767): An exception occured during performFiltering()!
java.lang.NullPointerException
04-21 11:23:48.819: WARN/Filter(16190):     
at android.widget.ArrayAdapter$ArrayFilter.performFiltering(ArrayAdapter.java:437)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.Looper.loop(Looper.java:144)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.HandlerThread.run(HandlerThread.java:60)

I don't really know what's going on here. The nC variable holds the name of the contacts to put into the AutoComplete, so that's not the problem..

4

3 回答 3

5

我发现了那个问题。它是由我在 arrayadapter 中的一项具有“null”值的属性引起的。

在您的情况下,“nC”元素之一必须为“null”。尝试在控制台中显示所有元素的列表,例如:System.out.println(index + ": " + nC[index]);并查找其中一个是否为空。

祝你好运!

于 2011-10-13T10:39:22.047 回答
1

例如,如果 nC 的长度为 10 并且您只有 9 个元素,您将得到该异常。

资源

于 2011-05-01T09:23:59.800 回答
1

根据上述评论中交换的信息:检查在 nC 中返回的数据。很可能你有一个没有名字的联系人。

于 2011-04-21T19:27:29.867 回答