0
當試圖執行所述第一正整數的擴展例如:診斷的NetLogo擴展命令錯誤
顯示噪聲:第一正整數5
我收到錯誤「ERROR:預期命令」在控制檯或代碼選項卡中。 我主要是複製和粘貼類示例,只是重命名並將它們放在不同的包中。我希望這個錯誤更具描述性,因爲我懷疑我在某處發生了一個簡單的錯誤。
我在沒有JRE的情況下使用5.0.4,而在x64 Windows 7機器上使用的是JRE/JDK 1.7.0_45。
具有完全限定類經理和CRLF在該版本的結束我的manifest.txt文件line--
Manifest-Version: 1.0
Extension-Name: noise
Class-Manager: org.xyz.extensions.NoiseExtension
NetLogo-Extension-API-Version: 5.0 <--there is a crlf here
罐子是一個子文件夾和我的模型文件
test/
test.nlogo
noise/
noise.jar
這是我的類經理:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseExtension extends DefaultClassManager {
public void load(PrimitiveManager primitiveManager) {
primitiveManager.addPrimitive(
"first-n-integers", new org.xyz.extensions.NoiseGenerator());
}
}
這是NoiseGenerator文件:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseGenerator extends DefaultReporter {
public Syntax getSyntax() {
return Syntax.reporterSyntax(
new int[] {Syntax.NumberType()}, Syntax.ListType());
}
public Object report(Argument args[], Context context) throws ExtensionException {
// create a NetLogo list for the result
LogoListBuilder list = new LogoListBuilder();
int n ;
// use typesafe helper method from
// org.nlogo.api.Argument to access argument
try {
n = args[0].getIntValue();
}
catch(LogoException e) {
throw new ExtensionException(e.getMessage()) ;
}
if (n < 0) {
// signals a NetLogo runtime error to the modeler
throw new ExtensionException
("input must be positive");
}
// populate the list. note that we use Double objects; NetLogo
// numbers are always Doubles
for (int i = 0; i < n; i++) {
list.add(Double.valueOf(i));
}
return list.toLogoList();
}}
感謝您的幫助。
AJB
更正的方法名稱和代碼現在可用。 – user3113257