第一次在堆栈溢出时摆姿势,所以请原谅任何遗漏的约定。让我知道,我将对其进行补救。
我无法以编程方式运行模型。我认为这是由于imageio无法读取jar或外部项目中的图像文件而导致的,我找不到解决该问题的方法。
当我正常运行模型时,一切都很好,但是当我从另一个项目中以编程方式运行它时,我得到:
首先警告:
log4j:WARN No appenders could be found for logger (org.java.plugin.boot.DefaultPluginsCollector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
然后GUI启动,当我按“开始运行”或“初始化运行”时,我得到:
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Caught NullPointerException: null on thread AWT-EventQueue-0
在我读了一个repast sourceforge邮件列表的内容之后,我认为与这里的其他内容无关,因为他们说此错误/警告GUI错误日志是要阅读的内容。 GUI中的记录器显示:
2019/03/05 09:12:32,297: Error while initializing edited style
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at repast.simphony.visualizationOGL2D.ImageSpatialSource.registerSource(ImageSpatialSource.java:52)
at repast.simphony.visualization.editedStyle.EditedStyleOGL2D.init(EditedStyleOGL2D.java:95)
at repast.simphony.visualizationOGL2D.DisplayOGL2D.registerStyle(DisplayOGL2D.java:475)
at repast.simphony.visualization.engine.DisplayCreatorOGL2D$2.register(DisplayCreatorOGL2D.java:81)
at repast.simphony.visualization.engine.DisplayCreatorOGL2D$2.register(DisplayCreatorOGL2D.java:1)
at repast.simphony.visualization.engine.StyleRegistrar.registerStyles(StyleRegistrar.java:93)
at repast.simphony.visualization.engine.StyleRegistrar.registerStyles(StyleRegistrar.java:34)
at repast.simphony.visualization.engine.DisplayCreatorOGL2D.createDisplay(DisplayCreatorOGL2D.java:79)
at repast.simphony.visualization.engine.DisplayProducer.createDisplay(DisplayProducer.java:48)
at repast.simphony.visualization.engine.DisplayComponentControllerAction.runInitialize(DisplayComponentControllerAction.java:116)
at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
此错误的冒犯代码(在模型中)必须为:
@Override
public Context build(Context<Object> context) {
try {
img = ImageIO.read(new File("maps/trondheimv2.png"));
} catch (IOException e) {
System.out.println(e + ": Image file not found!");
}
...
我尝试使用绝对路径:
C:/Users/USER/Documents/Git/REPO/Traffic_Main/maps/trondheimv2.png
和此方法:
getClass().getResource("C:/Users/USER/Documents/Git/REPO/Traffic_Main/maps/trondheimv2.png").toURI()));
我正在使用FAQ示例的重命名版本以编程方式运行模型:
package execute;
public class UserMain {
public UserMain () {};
public void start () {
String [] args = new String []{ "C:/Users/USERNAME/Documents/Git/REPO/Traffic_Main/CitySim.rs"};
repast . simphony . runtime . RepastMain . main ( args ) ;
}
public static void main ( String [] args ) {
UserMain um = new UserMain () ;
um . start () ;
}
}
该类在C:/ Users / USERNAME / Documents / Git / REPO / Runner / src / execute中的另一个项目中
我已经从repast.simphony.runtime_2.6.0 / lib中添加了jar,并将repast.simphony.runtime_2.6.0 / bin文件夹添加至了类路径。
我的目标是从Runner项目运行多个模型
谢谢您的时间。
编辑: 进行了 Eric Tatara 建议的更改,并出现以下错误:
WARN [AWT-EventQueue-0] 11:04:59,452 repast.simphony.ui.RSGUIConstants - Error loading: player_play, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,453 repast.simphony.ui.RSGUIConstants - Error loading: player_pause, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,454 repast.simphony.ui.RSGUIConstants - Error loading: player_stop, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,455 repast.simphony.ui.RSGUIConstants - Error loading: player_step, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,455 repast.simphony.ui.RSGUIConstants - Error loading: project_open, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,455 repast.simphony.ui.RSGUIConstants - Error loading: filesave, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,456 repast.simphony.ui.RSGUIConstants - Error loading: filesave16, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,456 repast.simphony.ui.RSGUIConstants - Error loading: filter16, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,457 repast.simphony.ui.RSGUIConstants - Error loading: reload, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,457 repast.simphony.ui.RSGUIConstants - Error loading: exec, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,457 repast.simphony.ui.RSGUIConstants - Error loading: folder, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,458 repast.simphony.ui.RSGUIConstants - Error loading: folder_open, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,458 repast.simphony.ui.RSGUIConstants - Error loading: camera, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,458 repast.simphony.ui.RSGUIConstants - Error loading: movie, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,459 repast.simphony.ui.RSGUIConstants - Error loading: chart, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,459 repast.simphony.ui.RSGUIConstants - Error loading: database, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,460 repast.simphony.ui.RSGUIConstants - Error loading: display, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,460 repast.simphony.ui.RSGUIConstants - Error loading: info_viz, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,460 repast.simphony.ui.RSGUIConstants - Error loading: kudesigner, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,461 repast.simphony.ui.RSGUIConstants - Error loading: lockstart_session, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,461 repast.simphony.ui.RSGUIConstants - Error loading: leaf, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,462 repast.simphony.ui.RSGUIConstants - Error loading: edit, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,462 repast.simphony.ui.RSGUIConstants - Error loading: home, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,462 repast.simphony.ui.RSGUIConstants - Error loading: info, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,463 repast.simphony.ui.RSGUIConstants - Error loading: view_sidetree, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,463 repast.simphony.ui.RSGUIConstants - Error loading: harddrive, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,463 repast.simphony.ui.RSGUIConstants - Error loading: button_cancel, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,464 repast.simphony.ui.RSGUIConstants - Error loading: edit_add, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,464 repast.simphony.ui.RSGUIConstants - Error loading: apply, it will not be used.
WARN [AWT-EventQueue-0] 11:04:59,464 repast.simphony.ui.RSGUIConstants - Error loading: redo, it will not be used.
FATAL [AWT-EventQueue-0] 11:04:59,545 repast.simphony.ui.RSUIPlugin - Fatal error starting Repast
java.lang.NoSuchMethodError: com.jgoodies.forms.layout.ColumnSpec.createGap(Lcom/jgoodies/forms/layout/ConstantSize;)Lcom/jgoodies/forms/layout/ColumnSpec;
at com.jgoodies.forms.layout.FormSpecs.<clinit>(FormSpecs.java:115)
at repast.simphony.ui.RunOptionsPanel.initComponents(RunOptionsPanel.java:114)
at repast.simphony.ui.RunOptionsPanel.<init>(RunOptionsPanel.java:39)
at repast.simphony.ui.RSGui.addRunOptionsView(RSGui.java:558)
at repast.simphony.ui.RSApplication.initGui(RSApplication.java:655)
at repast.simphony.ui.RSAppConfigurator.fillBars(RSAppConfigurator.java:52)
at saf.core.ui.GUICreatorDelegate.createDisplay(GUICreatorDelegate.java:189)
at saf.core.ui.GUICreator.createDisplay(GUICreator.java:12)
at repast.simphony.ui.RSUIPlugin$1.run(RSUIPlugin.java:99)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage.<init>(Unknown Source)
at repast.simphony.ui.widget.IconRotator.rotate(IconRotator.java:51)
at repast.simphony.ui.widget.IconRotator.access$0(IconRotator.java:47)
at repast.simphony.ui.widget.IconRotator$1.actionPerformed(IconRotator.java:32)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
答案 0 :(得分:0)
问题1:您需要将MessageCenter.log4j.properties文件复制到运行模型的文件夹中。
问题2:您发布的异常表明该错误是由于其中一台显示器的样式类编辑问题所致。如果使用编辑器创建显示样式并将图像文件分配给代理图标,则图像文件URL将存储在位于项目.rs文件夹中的显示描述符XML文件中。我怀疑图像文件的相对文件路径是在XML文件中定义的,并且如果从另一个文件夹启动代码,则相对路径将不正确。我建议直接编辑样式XML,或者使用绝对路径,或相应地更改相对路径,或者在运行时从中指向正确位置的文件夹中创建符号链接。