【问题标题】:getting strange stacktrace on compiling groovy class在编译 groovy 类时得到奇怪的堆栈跟踪
【发布时间】:2009-07-14 20:21:47
【问题描述】:

我正在用 Groovy 编写一个小型测试应用程序。我有以下代码。

class Address {

static constraints = {
    street(blank:false, maxSize:100)
    residencenumber(min:1, max:65000)
    addition()
    zip()
    city(blank:false, maxSize:100)
    county()
    country(blank:false, maxSize:50)
}

String street
String zip
int residencenumber
String addition
String city
String county
String country

String toString() {
    return street + " " + residencenumber + " " + zip + " " + city + " " + country
}

}

我收到了这条相当神秘的信息。

nojevive@follett:~/dev/code/mysmallapp$ grails generate-all 地址 欢迎使用 Grails 1.1.1 - http://grails.org/ 根据 Apache 标准许可证 2.0 获得许可 Grails home 设置为:/home/nojevive/dev/grails

基本目录:/home/nojevive/dev/code/mysmallapp 运行脚本 /home/nojevive/dev/grails/scripts/GenerateAll.groovy 环境设置为开发 groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call() is applicable for argument types: () values: [] at Project$__clinit__closure1.doCall(Project.groovy:11) at Project$__clinit__closure1.doCall(Project.groovy) at Project.getProperty(Project.groovy) at _PluginDependencies_groovy$_run_closure6_closure53.doCall(_PluginDependencies_groovy:467) at _PluginDependencies_groovy$_run_closure6_closure53.doCall(_PluginDependencies_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _PluginDependencies_groovy$_run_closure6.doCall(_PluginDependencies_groovy:447) at _GrailsBootstrap_groovy$_run_closure1.doCall(_GrailsBootstrap_groovy:74) at _GrailsGenerate_groovy$_run_closure1.doCall(_GrailsGenerate_groovy:37) at GenerateAll$_run_closure1.doCall(GenerateAll.groovy:42) at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:344) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:334) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.processTargets(Gant.groovy:495) at gant.Gant.processTargets(Gant.groovy:480) Error loading plugin manager: No signature of method: java.lang.Integer.call() is applicable for argument types: () values: []

首先我认为我的号码可能超出范围(我有 1000000)。然后我想也许这个号码是一个内置名称,所以我重命名为 Residencenumber。但没有运气。我在这里想念什么? 我现在删除了所有约束,但仍然是相同的消息。所以它与我猜的领域无关。一定是有什么东西坏了?

【问题讨论】:

  • 我清理了项目并重新编译。得到同样的错误。原来在另一个班级有错字?怎么需要在命令行指定域类 generate-all 然后好像又编译了另一个类?好吧,也许初学者很挣扎......
  • 我不久前参加了 Scott Davis 的 Grails 课程。我在课堂上学到的最重要的事情之一是,如果你遇到了一个非常奇怪且没有意义的错误,请对你的项目进行干净的重建。大约 90% 的时间有些东西不同步,只需要重新编译。

标签: groovy compiler-errors stack-trace


【解决方案1】:

我知道你已经解决了这个问题,但是更好的 toString 方法是:

String toString() {
  "$street $residencenumber $zip $city $country"
}

【讨论】:

  • Tim,java 是否支持使用 $ 作为字符串,或者只是 groovy?
【解决方案2】:

我可能错了,但我认为您正在将 int 添加到 String。一世 试试:

street + " " + residencenumber.toString() +...

【讨论】:

  • 我已经试过了,我在'street'之后把所有东西都砍掉了,但是没有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多