Question: Help me find my error please my program hangs and has out of memory errors. //prologue //plays audio file specified and runs an animation //import

Help me find my error please my program hangs and has out of memory errors.

//prologue\\ //plays audio file specified and runs an animation\\ //import import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.GridPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; import javafx.scene.control.*; import javafx.animation.Timeline; import javafx.animation.KeyFrame; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.geometry.Pos; import javafx.geometry.HPos; import javafx.util.Duration; public class SoundAnimation extends Application { // define protected class variables protected TextField tfSpeed; protected TextField tfPrefix; protected TextField tfNumberOfImages; protected TextField tfURL; protected StackPane paneForImage; protected Timeline animation; protected int n = 1; // Override the start method in class @Override public void start(Stage primaryStage) { tfSpeed = new TextField(); tfPrefix = new TextField(); tfNumberOfImages = new TextField(); tfURL = new TextField(); paneForImage = new StackPane(); final int COLUMN_COUNT = 27; tfSpeed.setPrefColumnCount(COLUMN_COUNT); tfPrefix.setPrefColumnCount(COLUMN_COUNT); tfNumberOfImages.setPrefColumnCount(COLUMN_COUNT); tfURL.setPrefColumnCount(COLUMN_COUNT); // Makes Button Button btStart = new Button("Start Animation"); // Creates grid pane for the labels and the text fields GridPane paneForInfo = new GridPane(); paneForInfo.setAlignment(Pos.CENTER); paneForInfo.add(new Label("Enter information for animation"), 0, 0); paneForInfo.add(new Label("Animation speed in milliseconds"), 0, 1); paneForInfo.add(new Label("Image file prefix"), 0, 2); paneForInfo.add(new Label("Number of images"), 0, 3); paneForInfo.add(new Label("Audio file URL"), 0, 4); paneForInfo.add(tfSpeed, 1, 1); paneForInfo.add(tfPrefix, 1, 2); paneForInfo.add(tfNumberOfImages, 1, 3); paneForInfo.add(tfURL, 1, 4); // Creates border pane BorderPane pane = new BorderPane(); pane.setBottom(paneForInfo); pane.setCenter(paneForImage); pane.setTop(btStart); pane.setAlignment(btStart, Pos.TOP_RIGHT); // Creates animation animation = new Timeline( new KeyFrame(Duration.millis(1000), e -> nextImage())); animation.setCycleCount(Timeline.INDEFINITE); // Make and registers handler btStart.setOnAction(e -> { if (tfURL.getText().length() > 0) { MediaPlayer mediaPlayer = new MediaPlayer(new Media(tfURL.getText())); mediaPlayer.play(); } if (tfSpeed.getText().length() > 0) animation.setRate(Integer.parseInt(tfSpeed.getText())); animation.play(); }); // Creates scene and places it Scene scene = new Scene(pane, 550, 680); // title for the stage primaryStage.setTitle("SoundAnimation"); // puts scene in stage primaryStage.setScene(scene); // show stage primaryStage.show(); } // Puts imageView in pane private void getImage() { paneForImage.getChildren().clear(); paneForImage.getChildren().add(new ImageView(new Image( "http://cs.armstrong.edu/liang/common/image/" + tfPrefix.getText() + n + ".gif"))); } //loads the next image private void nextImage() { n = n < Integer.parseInt( tfNumberOfImages.getText()) ? n += 1 : 1; getImage(); } // Main method of the program public static void main(String[] args) { launch(args); } }student submitted image, transcription available below

java lang. OutofMemoryError: Java heap space java lang. OutofMemoryError: Java heap space java.lang. OutofMemoryError: Java heap space

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!