如何在Intellij Idea中运行Kotlin函数 [英] How to run Kotlin function in Intellij Idea

查看:1466
本文介绍了如何在Intellij Idea中运行Kotlin函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个测试项目,旨在从IntelliJ IDEA CE中的Kotlin开始.

I have created a test project aiming to start with Kotlin in IntelliJ IDEA CE.

IDE版本和系统为2017.1.4 Build#IC-171.4694.23,于2017年6月6日构建 JRE:1.8.0_112-release-736-b21 x86_64 JVM:JetBrains s.r.o的OpenJDK 64位服务器VM Mac OS X 10.12.4

The IDE version and the system is 2017.1.4 Build #IC-171.4694.23, built on June 6, 2017 JRE: 1.8.0_112-release-736-b21 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.4

其中有一个具有主要功能的.kt文件.当我右键单击它时,我可以选择运行",但是会收到一个来自JUnit的错误消息:!希望使用JUnit版本3.8或更高版本.

There is one .kt file with a main function in it. When I right-click on it I can select Run, but I get an error form JUnit: !!! JUnit version 3.8 or later expected.

我发现这与缺少配置有关,但是我也无法为Kotlin设置合适的配置.也就是说,它需要一个主类",而我没有.相反,如其他一些讨论所建议的那样,设置软件包名称也无济于事.

I figured out it was about missing configuration, but I can't set up a proper one for Kotlin as well. Namely it requires a 'main class', which I don't have. Setting package name instead, as some other discussions suggest didn't help either.

在IDEA中Kotlin的正确配置是什么?

What is the proper configuration for Kotlin in IDEA?

谢谢!

推荐答案

检查您的IDEA是否为最新.创建新项目时,您可以像这样选择Kotlin:

Check that your IDEA is up to date. When creating a new Project you can select Kotlin like this:

这将自动为您配置Kotlin .如果您启动了Java项目并需要Kotlin支持,则右下角会出现一个小窗口,可以为您在项目中配置Kotlin. (如果如上所示创建项目,则不需要)

This will automatically configure Kotlin for you. If you started a Java project and want Kotlin support, there will be a little window in the bottom right corner to configure Kotlin in the project for you. (not needed if the project is created like shown above)

您要选择 Java ,而不是 Javascript ,然后单击"..."项目中的配置'..."模块作为Kotlin(Java)模块 ..."

There you want to select Java, not Javascript and after that click on "Configure '...' module in '...' project as Kotlin (Java) module..."

正确设置项目后,请确保您的主函数名为"main" ,并且参数类型为Array<String>.

When your project is set up correctly, make sure that your main function is called "main" and has a parameter of type Array<String>.

fun main(args: Array<String>) {

}

旁边将出现一个Kotlin "K" ,您可以单击它以运行您的主要功能.

Next to it a Kotlin "K" will appear, which you can click on to run your main function.

这篇关于如何在Intellij Idea中运行Kotlin函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆