Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimSample.java: anim is Never Initialized #1227

Closed
Harvalove opened this issue Feb 6, 2023 · 1 comment · Fixed by #1230
Closed

AnimSample.java: anim is Never Initialized #1227

Harvalove opened this issue Feb 6, 2023 · 1 comment · Fixed by #1230

Comments

@Harvalove
Copy link
Contributor

Hi,
The AnimSample throws a NullPointerException when pressing the f key. The anim variable is not initialized

Message:  Cannot invoke "com.almasb.fxgl.animation.Animation.onUpdate(double)" because "this.anim" is null
Type:  NullPointerException
Method:  AnimSample.lambda$initInput$1()
Line:  AnimSample.java:49

java.lang.NullPointerException: Cannot invoke "com.almasb.fxgl.animation.Animation.onUpdate(double)" because "this.anim" is null
	at samples.main@17 dev-SNAPSHOT/sandbox.anim.AnimSample.lambda$initInput$1(AnimSample.java:49)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.dsl.FXGL$Companion$onKeyDown$1.onActionBegin(FXGL.kt:488)
	at com.almasb.fxgl.core@17 dev-SNAPSHOT/com.almasb.fxgl.input.UserAction.begin$fxgl_core(UserAction.kt:37)
	at com.almasb.fxgl.core@17 dev-SNAPSHOT/com.almasb.fxgl.input.Input.handlePressed(Input.kt:375)
	at com.almasb.fxgl.core@17 dev-SNAPSHOT/com.almasb.fxgl.input.Input.onKeyEvent(Input.kt:318)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.app.PrimaryStageWindow$1$1.invoke(MainWindow.kt:308)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.app.PrimaryStageWindow$1$1.invoke(MainWindow.kt:308)
	at com.almasb.fxgl.core@17 dev-SNAPSHOT/com.almasb.fxgl.core.fsm.StateMachine.runOnActiveStates(StateMachine.kt:69)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.app.PrimaryStageWindow$1.invoke(MainWindow.kt:308)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.app.PrimaryStageWindow$1.invoke(MainWindow.kt:306)
	at com.almasb.fxgl.all@17 dev-SNAPSHOT/com.almasb.fxgl.app.MainWindow.addKeyHandler$lambda$1(MainWindow.kt:221)
	at [email protected]/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
	at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
	at [email protected]/javafx.scene.Scene$KeyHandler.process(Scene.java:4113)
	at [email protected]/javafx.scene.Scene.processKeyEvent(Scene.java:2159)
	at [email protected]/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2627)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:218)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:150)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:250)
	at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:249)
	at [email protected]/com.sun.glass.ui.View.handleKeyEvent(View.java:542)
	at [email protected]/com.sun.glass.ui.View.notifyKey(View.java:966)
	at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
	at java.base/java.lang.Thread.run(Thread.java:833)

@Harvalove
Copy link
Contributor Author

This fixes it but I'm not sure if that's the correct way of getting animation from the builder and still calling buildAndPlay

        builder= animationBuilder()
                .onCycleFinished(() -> System.out.println("Cycle finished"))
                .onFinished(() -> System.out.println("Anim finished"))
                .duration(Duration.seconds(1))
                .repeat(5)
                .scale(e)
                .origin(new Point2D(40, 40))
                .from(new Point2D(1, 1))
                .to(new Point2D(2, 2));

        anim = builder.build();
        builder.buildAndPlay();;
    }

Harvalove added a commit to Harvalove/FXGL that referenced this issue Feb 20, 2023
AlmasB pushed a commit that referenced this issue Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant