Finder Function Not Working, Base Adapter Invokes Nullpointer
this app has a textView for input and a button which invoke Finder function. The finder will find the input text in the array of strings and then display them in a listView. Follow
Solution 1:
Your getView()
of Adapter is returning null
value.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = new TextView(getApplicationContext());
}
((TextView) convertView).setText(searchList.get(position));
returnnull; // <<<<<< PROBLEM IS HERE
}
Which must return convertView as below
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = new TextView(getApplicationContext());
}
((TextView) convertView).setText(searchList.get(position));
return convertView;
}
Even other methods getItem()
and getItemId()
are not correctly defined. I would suggest you to read about these methods and how you should override them.
Till then these methods would be like
@Overridepublic Object getItem(int position) {
if (searchList == null || searchList.isEmpty()) {
returnnull;
} else {
return searchList.get(position);
}
}
@OverridepubliclonggetItemId(int position) {
return position; // Better is to return id field of data if you have
}
And as you are new here I would like to add one more thing, there are identical problem with answers, like java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference. So in future try to search first, learn from already answered questions.
Post a Comment for "Finder Function Not Working, Base Adapter Invokes Nullpointer"