Kotlin Parameter specified as non-null is null
报错信息如下:
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")
......
}
}
Kotlin Parameter specified as non-null is null的更多相关文章
- 数据库中is null(is not null)与=null(!=null)的区别
在标准SQL语言(ANIS SQL)SQL-92规定的Null值的比较取值结果都为False,既Null=Null取值也是False.NULL在这里是一种未知值,千变万化的变量,不是“空”这一个定值! ...
- mysql中NULL和null的区别
接触php的web开发一段时间了,在进行数据库操作的时候经常会遇到一个问题,使得同一字段在页面显示时有3种类型NULL,null以及数字,当时的解决办法是将这一字段定义为varchar类型,在插入数据 ...
- json-lib 中关于null与"null"
总感觉json-lib里面关于null和"null"的处理非常不合理,或者说是bug,去了json-lib的网站,最后一次更新是10年了... 发现官方网站第一段就说json-li ...
- 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 ...
- 【网络收集】MySql中IS NOT NULL与!=NULL的区别
在mysql中,筛选非空的时候经常会用到is not null和!=null,这两种方法单从字面上来看感觉是差不多的,其实如果去运行一下试试的话差别会很大!为什么会出现这种情况呢?null 表示什么也 ...
- Mysql 中is null 和 =null 的区别
在mysql中,筛选非空的时候经常会用到is not null和!=null,这两种方法单从字面上来看感觉是差不多的,其实如 果去运行一下试试的话差别会很大! 为什么会出现这种情况呢? null 表示 ...
- 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) ...
- MySQL timestamp NOT NULL插入NULL的问题
explicit_defaults_for_timestamp MySQL 5.6版本引入 explicit_defaults_for_timestamp 来控制对timestamp NULL值的处理 ...
- 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 ...
随机推荐
- JMeter多脚本间的启动延时
JMeter做压测时,当需要多个jmx脚本依次执行时,需要用到“启动延时”,即间隔可设置的时间后启动运行下一个jmx脚本. 实现“启动延时”的方法有2个. 方法一.利用JMeter线程组中的" ...
- 原生js的2048的制作过程
1.首先我们来看一下效果图 开始: 结束: 接下来我们来实现代码部分: HTML部分: 2048大家应该都玩过,首先我们要准备16个盒子让它4*4排列,这里的css我就不说了,这应该使我们都会的,在这 ...
- Java题库——Chapter14 JavaFX基础
Chapter 14 JavaFX Basics Section 14.2 JavaFX vs Swing and AWT1. Why is JavaFX preferred?a. JavaFX is ...
- 【原创】WinForm中实现单独Time控件的方式
WinForm默认只提供了DateTimePicker,今天的项目只用时间,不能出现日期,百撕不得骑姐(^^),也没花多少时间,随便试了一下,就成功了,分享一下. 在DateTimePicker属性中 ...
- Filter List Views 筛选器列表视图
In this lesson, you will learn how to filter a List View. Three techniques, based on different scena ...
- Git实战指南----跟着haibiscuit学Git(第三篇)
笔名: haibiscuit 博客园: https://www.cnblogs.com/haibiscuit/ Git地址: https://github.com/haibiscuit?tab=re ...
- SSM框架之SpringMVC(6)异常处理及拦截器
SpringMVC(6)异常处理及拦截器 1.异常处理 1.1.异常处理的思路 系统中异常包括两类:预期异常和运行时异常 RuntimeException,前者通过捕获异常从而获取异常信息,后者主 ...
- jsf中的按钮加弹框的两种形式
第一种: <p:commandButton value="一键移除" action="#{ProjectPackageManageBackingBean.remov ...
- 将CocoStudio产生的UI文件导入到项目
配置: Xcode 6.0 + CocoStudio 1.6 + Cocos2d-x 3.4 添加资源 将导出的资源文件放到 Resource 文件夹下. 头文件 #include "coc ...
- 论文阅读:EGNet: Edge Guidance Network for Salient Object Detection
论文地址:http://openaccess.thecvf.com/content_ICCV_2019/papers/Zhao_EGNet_Edge_Guidance_Network_for_Sali ...