kotlin 简单处理 回调参数 加?
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 简单处理 回调参数 加?的更多相关文章
- Win64 驱动内核编程-13.回调监控模块加载
回调监控模块加载 模块加载包括用户层模块(.DLL)和内核模块(.SYS)的加载.传统方法要监控这两者加在必须 HOOK 好几个函数,比如 NtCreateSection 和 NtLoadDriver ...
- asp.net 解决 "回发或回调参数无效" 一些常见解决方案
一.回发或回调参数无效,出现下图错误, 常见解决方案: 1.在页面的<%@ Page Language="C#" AutoEventWireup="true&qu ...
- 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。
问题补充: “/Source”应用程序中的服务器错误. 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或 ...
- asp.net 回发或回调参数无效的各种情况分析及解决办法
昨天,在实现级联菜单的时候,突然出现一下错误: 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中 ...
- jQuery:多个AJAX/JSON请求对应单个回调并行加载
因为我们使用jQuery,这意味着需要调用 jQuery.getScript 和 jQuery.getJSON 函数. 我知道这些函数都是异步执行(asyncronously)并且会延迟一段时间返回, ...
- 一个简单的AMD模块加载器
一个简单的AMD模块加载器 参考 https://github.com/JsAaron/NodeJs-Demo/tree/master/require PS Aaron大大的比我的完整 PS 这不是一 ...
- 点击datalist中Button按钮出现“回发或回调参数无效......”
遇到问题: 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page ...
- 学习加密(四)spring boot 使用RSA+AES混合加密,前后端传递参数加解密
学习加密(四)spring boot 使用RSA+AES混合加密,前后端传递参数加解密 技术标签: RSA AES RSA AES 混合加密 整合 前言: 为了提高安全性采用了RS ...
- System.ArgumentException: 回发或回调参数无效。在配置中使用 < pages enableEventValidation="true"/>
转载自http://blog.csdn.net/dongge825/article/details/7868151 关于在同一个页面中使用Gridview控件的时候发现气updaeting事件无法被服 ...
随机推荐
- 数据库oracle一些操作(MiTAC)
oracle计算时间差函数: 两个Date类型字段:START_DATE,END_DATE,计算这两个日期的时间差(分别以天,小时,分钟,秒,毫秒): 天: ROUND(TO_NUMBER(END_D ...
- JS基础_基本语法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- luogu P2605 [ZJOI2010]基站选址
luogu 先考虑朴素dp,设\(f_{i,j}\)表示在第\(i\)个村庄放了基站,一共放了\(j\)次,且只考虑前面村庄影响的答案.这里可以把\(j\)放在外面枚举,然后从\(f_{k,j-1}( ...
- debezium关于cdc的使用(上)
博文原址:debezium关于cdc的使用(上) 简介 debezium是一个为了捕获数据变更(cdc)的开源的分布式平台.启动并指向数据库,当其他应用对此数据库执行inserts.updates.d ...
- freemarker的replace的使用
1.replace替换: <#assign name="sdfsfdsa\ndfsafs\n"> 例子:${name?replace("\n",&q ...
- shell 脚本中的入参获取与判断
1.获取shell脚本的入参个数: $# 2.获取shell脚本的第n个入参的字符个数/字符串长度(注意这里的n需要替换为具体的数字,如果这个数字超过实际的入参个数,结果为0): ${#n}
- zencart批量设置热卖商品 best seller、点击最高最受欢迎产品 most popular
zencart批量设置某分类下热卖商品数 best seller ; ,,,,,); zencart批量设置某产品点击最高最受欢迎产品 most popular ; ,,,,,);
- wget下载与tar压缩/解压
目录 wget命令 下载整个网站 压缩与解压 小节 wget命令 Usage: wget [OPTION]... [URL]... # 后台运行 -b, --background go to back ...
- __stdcall、__cdcel、__fastcall 调用
常用的调用约定有stdcall,cdecl,fastcall,thiscall,naked call等,以下将 __stdcall.__cdecl和__fastcall三种函数调用协议加以比较,函数调 ...
- chomre 控制台断点调试
在上图蓝色圆圈中数字,它们分别代表: 1.停止断点调试 2.不跳入函数中去,继续执行下一行代码(F10) 3.跳入函数中去(F11) 4.从执行的函数中跳出 5.禁用所有的断点,不做任何调试 6.程序 ...