Anylogic 空指针异常在模型运行期间更新/更改 3D 对象的比例

问题描述 投票:0回答:1

我正在为学校项目使用 Anylogic 个人学习版 (PLE) Anylogic 允许获取 3Dbject 的当前比例值,例如从代理中派生的名为“汽车”的“我的汽车”,在模型运行期间使用两种方法;

    //staticAgent.getScale();
    mycar.getScale();         
                      Or
    //staticAgent.3DObj.getScale();
    mycar.car.getScale();

当我使用

更新/更改我的 3D 对象的比例时
     //nonStaticAgent.setScale();
     mycar newCar = new mycar();
     newCar.setScale(0.5);

     //it gives following error during code compilation

     The method setScale(double) is undefined for the type mycar.

但是,当我尝试使用

    mycar newCar = new mycar();
    //NonStaticAgent.3Dobject.setScale();
    newCar.car.setSize(0.5);

它在编译时没有给出任何错误,但是当我在模拟运行期间通过调用上述方法单击按钮来更改大小时,它给出以下

Error while executing user action
java.lang.NullPointerException
For more details see Console
At console
java.lang.NullPointerException
    at gettingsize.Main.executeShapeControlAction(Main.java:435)
    at gettingsize.Main$4.action(Main.java:496)
    at com.anylogic.engine.presentation.ShapeControl.executeAction(Unknown Source)
    at com.anylogic.engine.presentation.ShapeButton.executeUserAction(Unknown Source)
    at com.anylogic.engine.gui.ExperimentHost.executeUserAction(Unknown Source)
    at com.anylogic.engine.internal.webserver.a.onAction(Unknown Source)
    at com.anylogic.executor.basic.rest.BasicAnimationSessionController.lambda$null$3(BasicAnimationSessionController.java:71)
    at com.anylogic.engin.internal.webserver.d.acceptToAnimationSvgSession(Unknown Source)
    at com.anylogic.executor.basic.rest.BasicAnimationSessionController.lambda$startController$4(BasicAnimationSessionController.java:71)
    at spark.ResponseTransformerRouteImpl$1.handle(ResponseTransformerRouteImpl.java:47)
    at spark.http.matching.Routes.execute(Routes.java:61)
    at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:134)
    at com.anylogic.engine.internal.webserver.config.ALServerFactory$1.lambda$0(Unknown Source)
    at org.eclipse.jetty.servlets.QoSFilter.doFilter(QoSFilter.java:202)
    at com.anylogic.engine.internal.webserver.config.ALServerFactory$1.doHandle(Unknown Source)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1584)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle(Server.java:501)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
    at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
    at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
    at java.base/java.lang.Thread.run(Thread.java:834)
java nullpointerexception anylogic
1个回答
0
投票

如果您使用代码动态创建代理,您必须在更改此代理大小之前调用“createAndStart(...)”函数。对于您的情况,它可能是:

mycar newCar = new mycar();
newCar.createAndStart(this);
newCar.car.setSize(0.5);
© www.soinside.com 2019 - 2024. All rights reserved.