报错信息如下:


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. 使用shell脚本删除30天以前的文件

    #!/bin/bashlocation=/root/rmfind $location -mtime +30 -print | xargs rm -rf //-mtime是距离上一次修改时间 -prin ...

  2. [Linux] linux路由表

    路由表用于决定数据包从哪个网口发出,其主要判断依据是目标IP地址Linux路由表其实有2个主要概念:按顺序走路由策略,在路由策略对应的路由表中匹配规则路由策略(rule)路由表(table) 查看所有 ...

  3. 使用.NET Core 构建现代化的桌面应用

    我们今天要聊的内容主要桌面开发四个方面:Windows平台..NET Core 3 平台上的WPF,Winform, 应用打包解决方案 MSIX 和 XAML 群岛访问原来UWP的控件,让我们的应用程 ...

  4. wpf 模拟抖音很火的罗盘时钟,附源码,下载就能跑

    wpf 模拟抖音很火的罗盘时钟,附源码 前端时间突然发现,抖音火了个壁纸,就是黑底蕾丝~~~  错错错,黑底白字的罗盘时钟! 作为程序员的我,也觉得很新颖,所以想空了研究下,这不,空下来了就用wpf, ...

  5. How to: Recompile the Business Class Library 如何:重新编译业务类库

    The eXpressApp Framework supplies the Business Class Library that consists of three assemblies. eXpr ...

  6. js效果 整理

    整理中... 1.js获取页面及元素高度.宽度 其他参考文献:http://www.open-open.com/lib/view/open1420120422531.html js: 网页可见区域宽: ...

  7. 团队项目之Scrum5

    小组:BLACK PANDA 时间:2019.11.25   每天举行站立式会议 提供当天站立式会议照片一张 2 昨天已完成的工作 2 实现文章展示页面 完善后台的编辑功能接口 今天计划完成的工作 2 ...

  8. python捕捉详细异常堆栈的方法

    python中有 try——except 的方法捕获异常,可以获取到异常的种类以及自定义异常, 但是有时候对于debug测试来说,信息不全,比如说 触发异常的具体位置在哪: import traceb ...

  9. 32(1).层次聚类---AGNES

    层次聚类hierarchical clustering 试图在不同层次上对数据集进行划分,从而形成树形的聚类结构. 一. AGNES AGglomerative NESting:AGNES是一种常用的 ...

  10. JS高程中的垃圾回收机制与常见内存泄露的解决方法

    起因是因为想了解闭包的内存泄露机制,然后想起<js高级程序设计>中有关于垃圾回收机制的解析,之前没有很懂,过一年回头再看就懂了,写篇博客与大家分享一下. #内存的生命周期: 分配你所需要的 ...