一、报错信息 在使用 Groovy 闭包时 , 会报如下错误 : Exception in thread "main" groovy.lang.MissingMethodException: No signature non-zero exit value 1 二、解决方案 ---- 上述类型的错误 , 是由于闭包中传入参数错误导致的 ; Exception in thread "main" groovy.lang.MissingMethodException
object) { object.hello() } fun(new Student()) fun(new Worker()) // 下面的用法会报 // Caught: groovy.lang.MissingMethodException 异常 fun(new Farmer()) 报错信息 : Caught: groovy.lang.MissingMethodException: No signature of method: Farmer.hello getAt(java.lang.String), each(groovy.lang.Closure), split(groovy.lang.Closure), wait() groovy.lang.MissingMethodException object.hello() } } fun(new Student()) fun(new Worker()) // 下面的用法会报 // Caught: groovy.lang.MissingMethodException
} else { // 如果 + 符号后面既不是数字 , 又不是 Age 对象 // 直接抛出异常 throw new MissingMethodException } else { // 如果 + 符号后面既不是数字 , 又不是 Age 对象 // 直接抛出异常 throw new MissingMethodException 对象与不支持的类型相加 , 会直接抛出异常 println age + "100" 执行结果 : ageNumber : 118 ageNumber : 36 Caught: groovy.lang.MissingMethodException java.lang.Object), use(java.lang.Class, groovy.lang.Closure), use(java.util.List, groovy.lang.Closure) groovy.lang.MissingMethodException
hello 方法的类 , class Farmer {} 该该类实例对象传入 fun 方法作为参数 , fun(new Farmer()) 就会报如下错误 : Caught: groovy.lang.MissingMethodException getAt(java.lang.String), each(groovy.lang.Closure), split(groovy.lang.Closure), wait() groovy.lang.MissingMethodException object) { object.hello() } fun(new Student()) fun(new Worker()) // 下面的用法会报 Caught: groovy.lang.MissingMethodException
在 Groovy 脚本中调用 Thread 静态扩展方法 , Thread.hello{ printf "Hello" } 报如下错误 : HelloCaught: groovy.lang.MissingMethodException groovy.lang.Closure), getId(), yield(), sleep(long), sleep(long), split(groovy.lang.Closure) groovy.lang.MissingMethodException
encoding=UTF-8 Y:\002_WorkSpace\003_IDEA\Groovy_Demo\src\main\groovy\Groovy.groovy Caught: groovy.lang.MissingMethodException run(), run(java.io.File, [Ljava.lang.String;), find(), find(groovy.lang.Closure), any() groovy.lang.MissingMethodException
例如: class Demo implements zin,yan{} def demo = new Demo() demo.text() 将会输出MissingMethodException错误异常 Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.Object.text() is applicable java.lang.String), wait(), wait(long), tap(groovy.lang.Closure), wait(long, int), any() groovy.lang.MissingMethodException
System.MissingMethodException 以上两个报错其实原因时相同的,只是一个出现在编译前,一个出现在编译后,这种情况报错的原因一般是 : 同一个解决方案中有多个 类库,类库之间有引用关系
我们只需要实现那些实际调用的方法,但如果调用的方法在映射中不存在,则会引发MissingMethodException或 UnsupportedOperationException,具体取决于传递给调用的参数 int n) void h(String s, int n) } x = [ f: {println "f called"} ] as X x.f() // 正常的方法调用 x.g() // MissingMethodException 异常触发 x.g(5) // UnsupportedOperationException 异常触发 异常的类型取决于调用本身: MissingMethodException:如果调用的参数与接口/类中的参数不匹配
assert false } catch (e) { assert e instanceof MissingMethodException }
'Hubert'] == group.members try { group.setMembers(0, 'hubert') // Not index property } catch (MissingMethodException
, 没有定义参数列表 , 仍然向闭包中传入参数的话 , 在运行时会报错 , 参考 【错误记录】Groovy 运行报错 ( Exception in thread “main“ groovy.lang.MissingMethodException
如果是添加一个参数之后再调试,就会发现 System.MissingMethodException 找不到方法 System.MissingMethodException:“Method not found
Caused by: groovy.lang.MissingMethodException: No signature of method: build_90npnf01wae3avkxhn7ts5vqn.android
this); activationAttributes = (object[]) null; } throw new MissingMethodException (ParameterModifier[]) null, culture, (string[]) null, out state); } catch (MissingMethodException this); activationAttributes = (object[]) null; } throw new MissingMethodException
我们传入进去后就会出现下面的错误: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.function Integer, Integer, Integer) values: [4, 5, 6, 7] Possible solutions: function(int, int, int) groovy.lang.MissingMethodException
// println closureWithOneArg(12345678) //输出: groovy.lang.MissingMethodException: No signature of method println magicNumber(11)//groovy.lang.MissingMethodException: No signature of method: zinyan$_run_closure1
build() } catch (MissingMethodException e) { assert e.message.readLines().first() ==
originalType.GetConstructor(_parameterTypes); 7 if (baseConstructor == null) 8 throw new MissingMethodException
{ return (Profile)Activator.CreateInstance(x); } catch (MissingMethodException