我有一个 ArrayList,其中包含60-70个元素。我将适配器设置为AutoCompleteTextView,如下所示。
AutoCompleteTextView mRecipient = (AutoCompleteTextView) this.findViewById(R.id.recipient);
mRecipient.setThreshold(1);
Log.i("Array list", ""+names);// Here I got the arrayList
ArrayAdapter<String> nameadapter=new ArrayAdapter<String>(MyClass.this, android.R.layout.simple_list_item_1, names);
mRecipient.setAdapter(nameadapter);
但是下拉列表没有出现,我在Logcat中得到了一些警告(非错误)。
04-21 17:15:53.017: W/Filter(15093): An exception occured during performFiltering()!
04-21 17:15:53.017: W/Filter(15093): java.lang.NullPointerException
04-21 17:15:53.017: W/Filter(15093): at android.widget.ArrayAdapter$ArrayFilter.performFiltering(ArrayAdapter.java:437)
04-21 17:15:53.017: W/Filter(15093): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
04-21 17:15:53.017: W/Filter(15093): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 17:15:53.017: W/Filter(15093): at android.os.Looper.loop(Looper.java:123)
04-21 17:15:53.017: W/Filter(15093): at android.os.HandlerThread.run(HandlerThread.java:60)
此外我还有一个ListView,现在是空的。
有人可以弄清楚这个警告意味着什么吗?
答案 0 :(得分:4)
警告来自ArrayAdapter.performFiltering(CharSequence)
中的以下代码段:
String prefixString = prefix.toString().toLowerCase(); // entered by user
final ArrayList<T> values = mOriginalValues;
final int count = values.size();
final ArrayList<T> newValues = new ArrayList<T>(count); // this will be returned
for (int i = 0; i < count; i++) {
final T value = values.get(i); // in your case, 'value' is null at times
final String valueText = value.toString().toLowerCase(); // the warning
// First match against the whole, non-splitted value
if (valueText.startsWith(prefixString)) {
newValues.add(value);
} else {
final String[] words = valueText.split(" ");
final int wordCount = words.length;
for (int k = 0; k < wordCount; k++) {
if (words[k].startsWith(prefixString)) {
newValues.add(value);
break;
}
}
}
}
因此,请检查null
中的names
值。