Java.lang.illegalargumentexception: Can't Have A Viewtypecount < 1
I'm getting this error: java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1 I'm pretty sure I know exactly what's causing it, but I don't know how to fix it. My
Solution 1:
I think you miss the point of ViewTypeCount. You should return the number of Different View Types in your list. This is important for recycling of the Views inside the List.
Imaging you have 2 Types of Listitems, one with a white Background and one with black Background. When you return 2 as ViewTypeCount the Listview knows ok, there a 2 types of Listitems and will not mix them up in the getView view recycling.
so just use:
publicintgetViewTypeCount() {
return1;
}
or dont override that method at all.
Solution 2:
Use this
@OverridepublicintgetViewTypeCount() {
if(getCount() > 0){
return getCount();
}else{
returnsuper.getViewTypeCount();
}
}
Solution 3:
getViewTypeCount returns the number of different types of views this adaptor can return. Since you're only returning one type of view, this should just return 1.
Solution 4:
Change this function in your Adapter class:
@Override
publicintgetViewTypeCount() {
return getCount();
}
to:
publicintgetViewTypeCount() {
if(getCount()<1) return1;
return getCount();
}
**note: avoid @Override
Post a Comment for "Java.lang.illegalargumentexception: Can't Have A Viewtypecount < 1"