报错信息如下:


java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter animation
at cn.enjoytoday.expandmateriallayout.ExpandRefreshLayout$mRefreshListener$1.onAnimationEnd(ExpandRefreshLayout.kt:0)
at cn.enjoytoday.expandmateriallayout.ExpandRefreshLayout$HeadViewContainer.onAnimationEnd(ExpandRefreshLayout.kt:1099)
at android.view.ViewGroup.finishAnimatingView(ViewGroup.java:6293)
at android.view.View.draw(View.java:17180)
......

kotlin 中对于回调对象若是为说明可以为空的情况下,kotlin 会自动对齐对象进行非空检查,就会报出如上错误,检查代码发现是设置接口的参数和创建的接口的回调参数的类型设置不一致,如下:


//创建的接口:
private animationListener = object: Animation.AnimationListener {
override fun onAnimationStart(animation:Animation) {
......
} override fun onAnimationRepeat(animation:Animation) {} override fun onAnimationEnd(animation:Animation) {
log(message = "onAnimationEnd")
......
} } //监听的类的声明
class CustomLayout(context:Context):LinearLayout(context){
private var listener: Animation.AnimationListener? = null fun setAnimationListener(listener: Animation.AnimationListener?) {
this.listener = listener
} public override fun onAnimationStart() {
super.onAnimationStart()
log(message = "onAnimationStart animation is null :${animation==null}")
listener?.onAnimationStart(this.animation)
} public override fun onAnimationEnd() {
super.onAnimationEnd()
log(message = "onAnimationEnd animation is null :${animation==null}")
listener?.onAnimationEnd(this.animation) } } //使用
fun useMethod(){
val layout=CustomLayout(context)
val animation=ScaleAnimation(1f, 0f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
layout.setAnimationListener(animationListener)
layout.clearAnimation()
layout.startAnimation(animation)
}

如上代码所示,通过运行 useMethod 方法,出现 “Parameter specified as non-null is null”报错,解决方法很简单,将我们设置的接口回调参数设置为可空类型即可,如下:


//创建的接口,目前就log看可知,onAnimationStart时animation为非空,onAnimationEnd为空
//因此,也可单独只对onAnimationEnd(animation:Animation)修改.
private animationListener = object: Animation.AnimationListener {
override fun onAnimationStart(animation:Animation?) {
......
} override fun onAnimationRepeat(animation:Animation?) {} override fun onAnimationEnd(animation:Animation?) {
log(message = "onAnimationEnd")
......
} }

Enjoytoday,EnjoyCoding

Kotlin Parameter specified as non-null is null的更多相关文章

  1. 数据库中is null(is not null)与=null(!=null)的区别

    在标准SQL语言(ANIS SQL)SQL-92规定的Null值的比较取值结果都为False,既Null=Null取值也是False.NULL在这里是一种未知值,千变万化的变量,不是“空”这一个定值! ...

  2. mysql中NULL和null的区别

    接触php的web开发一段时间了,在进行数据库操作的时候经常会遇到一个问题,使得同一字段在页面显示时有3种类型NULL,null以及数字,当时的解决办法是将这一字段定义为varchar类型,在插入数据 ...

  3. json-lib 中关于null与"null"

    总感觉json-lib里面关于null和"null"的处理非常不合理,或者说是bug,去了json-lib的网站,最后一次更新是10年了... 发现官方网站第一段就说json-li ...

  4. Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1

    Reference link: http://unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-nu ...

  5. 【网络收集】MySql中IS NOT NULL与!=NULL的区别

    在mysql中,筛选非空的时候经常会用到is not null和!=null,这两种方法单从字面上来看感觉是差不多的,其实如果去运行一下试试的话差别会很大!为什么会出现这种情况呢?null 表示什么也 ...

  6. Mysql 中is null 和 =null 的区别

    在mysql中,筛选非空的时候经常会用到is not null和!=null,这两种方法单从字面上来看感觉是差不多的,其实如 果去运行一下试试的话差别会很大! 为什么会出现这种情况呢? null 表示 ...

  7. 8.2.1.8 IS NULL Optimization NULL 优化:

    8.2.1.8 IS NULL Optimization NULL 优化: Oracle 对待null值: SQL> create table t100(id int,name char(10) ...

  8. MySQL timestamp NOT NULL插入NULL的问题

    explicit_defaults_for_timestamp MySQL 5.6版本引入 explicit_defaults_for_timestamp 来控制对timestamp NULL值的处理 ...

  9. ORA-20002: [WF_NO_USER] NAME=<name> ORIG_SYSTEM=NULL ORIG_SYSTEM_ID=NULL

    Solution APPLIES TO: Identity Manager Connector - Version 10.1.2 to 10.1.2Oracle User Management - V ...

随机推荐

  1. styled-components:解决react的css无法作为组件私有样式的问题

    react中的css在一个文件中导入,是全局的,对其他组件标签都会有影响. 使用styled-components第三方模块来解决,并且styled-components还可以将标签和样式写到一起,作 ...

  2. 替换空格(剑指offer_5)

    题目描述: 将一个字符串中的空格替换成"%20". Input: "A B" Output: "A%20B" 解题思路: 在字符串尾部填充任 ...

  3. jimdb压测踩坑记

    本文记录在jimdb压测过程中遇到的各种小坑,望能够抛砖引玉. 1.压测流量起来后,过了5分钟左右,发现ops突降,大概降了三分之一,然后稳定了下来 大概原因:此种情况,jimdb极有可能某个分片的连 ...

  4. c代码中while循环的一个死机问题引发的思考

    前记   c语言已经是一门经常吃饭的本领,本来是要有种看一眼,就知道哪儿出问题了才行,没想到,遇到实际问题的时候,才知道自己的修为不到家.还没有达到那种炉火纯青的境界.看来,不是这个世界没有机会,是自 ...

  5. UWP 在非UI线程中更新UI

    大家都知道,不可以在 其他线程访问 UI 线程,访问 UI 线程包括给 依赖属性设置值.读取依赖属性.调用方法(如果方法里面修改了依赖属性)等.一旦访问UI线程,那么就会报错,为了解决这个问题,需要使 ...

  6. Axure导出的原型无法在谷歌浏览器浏览

    1.下载crx后缀的文件. 2.修改crx后缀名为rar的压缩文件 3.解压刚才的rar文件 4.打开谷歌浏览器右上角的三个点 更多工具==>扩展程序 选择刚才的解压文件夹. 上面的图表示安装成 ...

  7. Dynamics 365 Customer Engagement导入解决方案时出错:Microsoft.Crm.CrmException: Plug-in assembly does not contain the required types or assembly content cannot be updated.

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  8. 与用户xxx一起提供的密码不正确。请确认输入的密码正确并重试

    环境: SharePoint 2010 / 2013 以系统账户身份登录管理中心,然后创建Web Application,报: 与用户xxx一起提供的密码不正确.请确认输入的密码正确并重试 明明都已经 ...

  9. Mybatis XML映射文件

    mybatis为聚焦于SQL而构建,SQL映射文件常用的顶级元素如 resultMap,是最复杂也是最强大的元素,用来描述如何从数据库结果集中来加载对象. insert,映射插入语句 update, ...

  10. Data Guard:Oracle 12c –新增和更新的功能 (Doc ID 1558256.1)

    Data Guard: Oracle 12c – New and updated Features (Doc ID 1558256.1) APPLIES TO: Oracle Database - E ...