无法在Android Studio中运行Scratch文件

时间:2019-06-14 10:54:32

标签: java android kotlin scratch-file

我正在尝试在Android Studio 3.4.1中运行Scratch文件,但无法看到输出。我创建了两个文件,一个文件扩展名为.kts,另一个文件扩展名为.java。

下面提到的是.kts文件

class Check {

fun main(args: Array<String>) {
    println(args[0]+"Hello, World!")
}

}

根据这个问题Kotlin scratch file output is missing in Android Studio,我们可以通过在顶层编写print语句来运行此文件,但错误仍然相同。下面提到的是错误:

  

“ C:\ Program Files \ Android \ Android Studio1 \ jre \ bin \ java.exe”   “ -javaagent:C:\ Program Files \ Android \ Android   Studio1 \ lib \ idea_rt.jar = 8940:C:\ Program Files \ Android \ Android   Studio1 \ bin“ -Dfile.encoding = windows-1252 -classpath” C:\ Program   文件\ Android \ Android   Studio1 \ plugins \ Kotlin \ kotlinc \ lib \ kotlin-compiler.jar; C:\ Program   文件\ Android \ Android   Studio1 \ plugins \ Kotlin \ kotlinc \ lib \ kotlin-reflect.jar; C:\ Program   文件\ Android \ Android   Studio1 \ plugins \ Kotlin \ kotlinc \ lib \ kotlin-stdlib.jar; C:\ Program   文件\ Android \ Android   Studio1 \ plugins \ Kotlin \ kotlinc \ lib \ kotlin-script-runtime.jar“   org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -kotlin-home“ C:\ Program   Files \ Android \ Android Studio1 \ plugins \ Kotlin \ kotlinc“-脚本   C:/Users/ch-e01460.SPICEMONEY/.AndroidStudio3.4/config/scratches/scratch.kts

当我尝试运行此.Java文件

class Scratch {
 public static void main(String[] args) {
    println("Hello, World!");
}
}

我收到以下提到的错误

  

错误:无法找到或加载主类暂存过程完成   退出代码1

我已经检查了许多其他可用的解决方案,但是没有一个对我有用。要求这里的所有人启发道路,以便它也可以对其他人有所帮助。预先感谢。

1 个答案:

答案 0 :(得分:1)

您不需要所有主类代码-暂存基本上是脚本。

可以创建并运行一个基本的scratch.kts文件:

  1. 右键单击要在其中创建临时文件的位置,例如Scratches and Consoles -> scratches并选择New -> scratch file
  2. 选择“科特琳”
  3. 输入代码println("Hello World!")
  4. 右键单击文件名,然后选择Run [scratch file].kts

这将创建一个运行配置,供以后使用。

Run

当您运行hello world示例时: Result