[英]Why does my Android Studio code randomly get underlined in red even when there is no error?
Sometimes my code gets randomly underlined in red even when there is no error 有时即使没有错误,我的代码也会随机用红色下划线
For example, in my Kotlin code (screenshot above): 例如,在我的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 of any random variables gets underlined in red. 任何随机变量的findViewById用红色加下划线。 When I copy the text, remove it, and paste it back, the "error" is removed.
当我复制文本,将其删除并粘贴回去时,“错误”将被删除。 Furthermore, the red line doesn't stop the code from compiling or executing, the application works perfectly, but in Android Studio, some random line like findViewById or other straightforward code will get underlined in red.
此外,红线不会阻止代码的编译或执行,该应用程序可以正常运行,但是在Android Studio中,某些随机行(如findViewById或其他简单代码)将以红色下划线。
The error for the above example reads: 上面示例的错误为:
Cannot infer type parameter T in
无法推断类型参数T in
fun findViewById ( id:Int ) :T!
有趣的findViewById(id:Int):T! None of the following substitutions ( Int) ( Int) ( Int) can be applied to ( Int)
以下替换(Int)(Int)(Int)均不能应用于(Int)
Any idea why this happens? 知道为什么会这样吗? I'm using Android Studio 3.1.3, 4th June 2018 build
我正在使用Android Studio 3.1.3,2018年6月4日构建
Because Kotlin compiler cannot infer the specific type for your variables. 因为Kotlin编译器无法推断变量的特定类型。 To dismiss this red line you could you 2 ways.
要消除这条红线,您可以选择2种方式。
The former: 前者:
private lateinit var nameTextView: TextView
nameTextView = findViewById(R.id.nameDashboardTextView)
The latter: 后者:
nameTextView = findViewById<TextView>(R.id.nameDashboardTextView)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.