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事件无法被服 ...
随机推荐
- idea 修改pom文件jdk版本回退问题解决
在Java开发是我们大多都使用集成开发环境,像idea和eclipse用的都比较多,在使用idea maven构建项目时,在修改pom.xml文件时,我们的项目jdk版本都会回退,还得每次去设置中修改 ...
- [Nest] 02.nest之控制器
控制器 Controller Nest 的核心概念 模块 Module 控制器 Controller 服务与依赖注入 Provider Dependency injection 控制器负责处理应用的特 ...
- JS基础_其他进制的数字(了解)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 数据库命令行工具USQL、mycli、litecli、pgcli
USQL USQL 是一款使用 Go 语言开发的支持 SQL/NoSQL 数据库的通用命令行工具,它支持多种主流的数据库软件,目前最新版本是usql 0.7.0.比如 PostgreSQL.MySQL ...
- vue+webpack项目环境搭建
首先安装node.js 下载地址:https://nodejs.org/en/download/ 看下是否成功安装 node -v 安装webpack,命令行npm install webpack - ...
- 运维学习篇之jenkins的安装(CentOS7)
一. 介绍 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能二. 作用 1.持续的软件版本 ...
- 基于Chromium的浏览器已上线通用“显示密码”按钮
基于Chromium的Edge在日前发布的Canary通道版本中,对用户界面进行了优化调整从而让InPrivate窗口变得更加简洁.在今天获得的版本更新中,微软继续带来了隐私相关的新内容--实现通用的 ...
- composer问题集锦
问题一:composer遇到Your configuration does not allow connection to 解决方案: 设置一个本地或全局的composer配置: composer c ...
- Cuda9.0安装
CUDA 9.0安装笔记 最近实验室新购买两块K80的GPU.作为好奇的小猪,当然会自报奋勇去配置环境.在这篇博客中将会介绍在centos7下配置CUDA 9.0的步骤. 1. 什么是CUDA? 引用 ...
- trigger添加及表达式
创建触发器 点击Configuration(配置) → Hosts(主机) 点击hosts(主机)相关行的trigger 点击右上角的创建触发器(create trigger) name : 触发器名 ...