首页 > 解决方案 > 为什么即使没有错误,我的 Android Studio 代码也会随机出现红色下划线?

问题描述

有时即使没有错误,我的代码也会随机用红色下划线

图片在这里

例如,在我的 Kotlin 代码中(上面的截图):

    nameTextView=findViewById(R.id.nameDashboardTextView)
    ageTextView=findViewById(R.id.ageDashboardTextView)
    emailIDTextView=findViewById(R.id.emailIDTextView)
    genderTextView=findViewById(R.id.genderTextView)
    weightTextView=findViewById(R.id.weightTextView)
    heightTextView=findViewById(R.id.heightTextView)
    progressBar3=findViewById(R.id.progressBar3)

任何随机变量的 findViewById 都带有红色下划线。当我复制文本,将其删除并将其粘贴回来时,“错误”被删除。此外,红线不会阻止代码编译或执行,应用程序运行良好,但在 Android Studio 中,一些随机行,如 findViewById 或其他简单的代码,将带有红色下划线。

上述示例的错误为:

无法推断类型参数 T in

有趣的 findViewById (id:Int) :T!以下替换 (Int) (Int) (Int) 均不能应用于 (Int)

知道为什么会这样吗?我正在使用 Android Studio 3.1.3,2018 年 6 月 4 日构建

标签: javaandroidandroid-studiokotlin

解决方案


推荐阅读