【问题标题】:groovy.lang.GroovyRuntimeException - Groovy errorgroovy.lang.GroovyRuntimeException - Groovy 错误
【发布时间】:2016-02-28 23:13:18
【问题描述】:

我一直在 Groovy 中进行一些测试。我已经完成了这段代码,我得到了这个错误

捕获:groovy.lang.GroovyRuntimeException:无法运行此脚本或类。 它应该:

  • 有一个main方法,

  • 成为 JUnit 测试或扩展 GroovyTestCase,

  • 实现 Runnable 接口,
  • 或与已注册的脚本运行程序兼容。知名跑者: 无

class Prime {

public static def prime(int x){ 
    boolean result = true;
    int i, j, temp;
    temp = 0;

    if (x < 2){
        result = false;
    }else {
        for(i = 2; i < x && j == 0; i++){
            temp = x % i;
            if(temp == 0){
                result = false;
            }
        }
    }
    return result;
}

static void main() {

    long time_start, time_end, time_exe;
    int primes = 0;
    int N = (int) Math.pow(8, 5);

    time_start = System.currentTimeMillis();

    def fichero = new File("salida2.out")

    for (int i = 0; i <= N; i ++) {
      if (prime(i)  == true) {
        String line =  "" + i + " is prime.";
        fichero.append(line);

      }
    }

    time_end = System.currentTimeMillis();

    time_exe = time_end - time_start;

    println("Execution time: " + time_exe + "milliseconds");
    println("Prime Numbers Found: " + primes);
}

}

【问题讨论】:

  • 我假设问题是“我做错了什么?”如果是这样,你的帖子应该清楚地表明问题是什么。

标签: groovy


【解决方案1】:

您的主要方法的签名不正确(需要字符串...参数)。

改成:

public static void main(String... args) {

【讨论】:

  • 是的,@pczeus,你完全正确,祝你有美好的一天。谢谢哟
  • @Manuel,如果这个答案解决了你的问题,请考虑接受它。
  • in groovy static main(args) 就足够了
  • 是的,这是真的蒂姆。
猜你喜欢
  • 1970-01-01
  • 2013-05-26
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多