问题描述
我刚刚开始使用 Android Studio 4.1.3 学习 Kotlin。
当我试图在新的 Test.kt 文件上运行一个非常简单的代码(只打印一个字)时,我收到此错误:
我在网上搜索,但我无法弄清楚这个错误的根源是什么。 谢谢
解决方法
您不能将 kotlin 文件放在 app/src/main/res/*
目录中。它需要进入 app/src/main/java/*
@Peyman 因为您刚刚开始,所以我将简要介绍如何构建应用程序。转到文件 -> 新建项目 -> 空活动 -> 填写表单并单击完成。您将自动导航到活动。然后你会看到你的项目结构如下:
app ->
src ->
main ->
java -> // this is where you will create hello.kt file. just click on the folder,create a package inside the package create .kt file -> like class Hello: Fragment (or AppCompatActivity) {... other stuff}
res -> // this is where you will create UI files such as hello.xml