美文网首页
ListView在removeFooterView时抛出异常

ListView在removeFooterView时抛出异常

作者: zii4914 | 来源:发表于2017-06-19 11:13 被阅读27次

异常:cannot be cast to android.widget.HeaderViewListAdapter

原因:在4.4以前(API19)的系统中,要求必须在setAdapter(adapter)之前调用addFooterView(footer),否则就会引发该异常。在4.4以后就没有这样的要求了。

addFooterView() 在API level 15说明:

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.

现在:

Note: When first introduced, this method could only be called before setting the adapter with {@link #setAdapter(ListAdapter)}. Starting with {@link android.os.Build.VERSION_CODES#KITKAT}, this method may be called at any time. If the ListView's adapter does not extend {@link HeaderViewListAdapter}, it will be wrapped with a supporting instance of {@link WrapperListAdapter}.

相关文章

  • ListView在removeFooterView时抛出异常

    异常:cannot be cast to android.widget.HeaderViewListAdapter...

  • ListView在removeFooterView时报java.

    这些天遇到一个很奇怪的问题,很奇怪的问题,很奇怪的问题。重要的事情要说三遍。奇怪的问题大都是在解决之间很奇怪,如果...

  • 子类继承父类方法

    父类方法抛出异常,子类继承父类,重写父类方法时,抛出的异常“子类抛出的异常类型不能比父类抛出的异常类型更宽泛”。 ...

  • Java中使用JDK代理时避免UndeclaredThrowab

    当InvocationHandler抛出运行时异常时,异常会被直接抛出。但如果抛出未在接口中声明的受检异常,就会被...

  • 一次线上java.util.ConcurrentModifica

    异常抛出原因 在使用remove方法对ArrayList进行删除操作时,会抛出此异常。 代码分析 测试用户类: 各...

  • BindException与MethodArgumentNotV

    基于表单提交时,参数校验异常,会抛出:BindException基于json提交时,参数校验异常,会抛出:Meth...

  • [转]构造函数、析构函数抛出异常的问题

    构造函数、析构函数抛出异常的问题 抛出异常1.1 抛出异常(也称为抛弃异常)即检测是否产生异常,在C++中,其采用...

  • 异常

    BatchUpdateException批量更新时抛出。该异常保存了异常发生前每条更新命令的返回值。抛出该异常后,...

  • Java15-1 覆盖中异常的使用

    先看代码 覆盖时,子类方法覆盖父类方法,只能抛出父类方法异常或者该异常的子类如果父类方法抛出多个异常,子类只能抛出...

  • Can not perform this action afte

    异常如下: 在使用fragment、dialogFragment等控件时可能会遇到以上异常。原因正如抛出的异常所说...

网友评论

      本文标题:ListView在removeFooterView时抛出异常

      本文链接:https://www.haomeiwen.com/subject/jwzlxxtx.html