N_CLASSES = 2
Ni_temp = []
Nij_temp = []
aap = 0
Nij_temp = [
[37, 2, ],
[3, 4, ],
]
for(i=0; i<N_CLASSES; i++)
{
Ni_temp[i] = 0
for(j=0; j<N_CLASSES; j++)
{
Ni_temp[i] += Nij_temp[j][i]
}
print "Ni_temp ${i} = ${Ni_temp[i]}"
}
**On one computer, we can execute this code correctly in the Groovy console;
the output is:
Ni_temp 0 = 40Ni_temp 1 = 6
**On another computer however, we get an exception, namely :
Exception thrown
nov 02, 2011 3:27:04 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
groovy.lang.MissingMethodException: No signature of method:
java.lang.Integer.getAt() is applicable for argument types:
(java.lang.Integer) values: [37]
Possible solutions: getAt(java.lang.String), next(),
putAt(java.lang.String, java.lang.Object), wait(), grep(), getClass()
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at
org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:55)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at ConsoleScript0.run(ConsoleScript0:17)
at
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
at groovy.lang.GroovyShell.run(GroovyShell.java:517)
at groovy.lang.GroovyShell.run(GroovyShell.java:172)
at groovy.lang.GroovyShell$run.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at
groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:924)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883)
at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883)
at groovy.lang.Closure.call(Closure.java:410)
at groovy.lang.Closure.call(Closure.java:404)
at groovy.lang.Closure.run(Closure.java:488)
at java.lang.Thread.run(Thread.java:722)
groovy.lang.MissingMethodException: No signature of method:
java.lang.Integer.getAt() is applicable for argument types:
(java.lang.Integer) values: [37]
Possible solutions: getAt(java.lang.String), next(),
putAt(java.lang.String, java.lang.Object), wait(), grep(), getClass()
at ConsoleScript0.run(ConsoleScript0:17)
<b>**Why does this code not work on one computer, because we think that
the code should be executed without error, since it looks to be valid Groovy
syntax. Can someone please help us ? Many thanks in advance ....
Dosti
--
View this message in context: http://groovy.329449.n5.nabble.com/non-reproducable-exception-tp4959888p4959888.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Instead, I would like to propose to you to work around your problem by
coding in a different way. Generally, for loops are not a very groovy
way of processing collections. There are various other paths you could
explore, `collection.each { ... }` being only the beginning. For
example, your problem of summing the elements of sublists could be
more succinctly solved like this:
Nij_temp.transpose()*.sum()
and I bet it will work on both of your computers.
For learning more you could try:
* Groovy in Action, 2nd ed. (MEAP from Manning)
* http://groovy.codehaus.org/Documentation
* stackoverflow
* this mailing list
Cheers,
Dinko