【问题标题】:Griffon / Groovy programming error : don't understandGriffon / Groovy 编程错误:不明白
【发布时间】:2014-10-08 09:41:40
【问题描述】:

我已经重写了这个问题,因为我已经本地化了问题但不理解它..

我正在试验 Griffon .. 在视图类中我有一些代码 ..

new Timer(1000, { e ->
    controller.countDown()
} as ActionListener).start()

效果很好(它在相应视图上驱动倒计时时钟,所以我不确定它的正确放置位置..但它可以工作)

我将代码移动到相应控制器 mvcGroupInit 例程中的控制器并得到一个错误..所以我将实现更改为 Java ..

Timer myTimer = new Timer(1000, new ActionListener() {
      void actionPerformed(ActionEvent e) {
            //countDown()
            println "Mmm ? "
        }
} )

我得到一个错误..

2014-10-08 10:13:46,695 [main] INFO  griffon.swing.SwingApplication - Initializing all startup   groups: [sequenceMonitor]
2014-10-08 10:13:49,391 [main] ERROR griffon.util.GriffonExceptionHandler - Uncaught Exception
groovy.lang.GroovyRuntimeException: Could not find matching constructor for:     java.util.Timer(java.lang.Integer, sequencemonitor.SequenceMonitorController$1)
at sequencemonitor.SequenceMonitorController.mvcGroupInit(SequenceMonitorController.groovy:36)  

指向

   Timer myTimer = new Timer(1000, new ActionListener() {
        void actionPerformed(ActionEvent e) { ....

所以我把代码复制到了 groovy 控制台..

import java.awt.event.*

new Timer(1000, {e->
   println "running .." 
} as ActionListener).start()   

然后运行它..得到了

WARNING: Sanitizing stacktrace:

    groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Timer(java.lang.Integer, com.sun.proxy.$Proxy12)

at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1550)

at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1404)

at  org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSit e.java:46)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:194)

at ConsoleScript9.run(ConsoleScript9:3)

我不明白为什么 Groovy 反对。有人可以启发我吗?这也是放置这种计时器的合理位置,因为它更新了反映在 UI 中的模型..

我正在使用 Griffon 1.4 / Java 1.7 / .. 再次感谢..

【问题讨论】:

    标签: groovy griffon


    【解决方案1】:

    你得到了错误的Timer 类(默认情况下):java.util.Timer 存在,因为来自java.util 的所有内容都会自动导入到 groovy 中。改用 FQN:

     new javax.swing.Timer(1000, ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多