android - 类型不匹配 : inferred type is Context? 但需要上下文 - Kotlin

标签 android kotlin

将 kotlin 版本更新到 1.3.0 后,我遇到了上述问题

下面是代码,

     public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAttr: Int)
: FrameLayout(context, attrs, defStyleAttr), ViewTreeObserver.OnGlobalLayoutListener {

}

第一行我明白了。问题 。请帮我解决这个问题。

最佳答案

签名错误。创建 View 时 Context 不能为 null,而 AttributeSet 可以。改变它就像

 public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

关于android - 类型不匹配 : inferred type is Context? 但需要上下文 - Kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55257199/

相关文章:

android - 是否可以通过 make 或 Soong 构建使用 Kotlin 的 Android 应用程序?

kotlin - 来自插件的 gradle 多项目任务配置 - 如何配置每个项目?

android - 在 Android 中应用程序崩溃时截取屏幕截图

java - SimpleDateFormat 无法解析的日期异常

java - 获取有关所有正在运行的进程的信息

android - Xamarin 选择 TargetFramework 和 MinimumAndroidVersion

android - Kotlin 函数需要 Nothing but defined as a different type

java - 二进制 XML 文件行 #23 : Error inflating class com. example.caesar.library.ChipView

kotlin - 如何在Kotlin中用单行值声明列表?

kotlin - 如何制作 Kotlin 可比类型?