如何调试崩溃的JavaFX程序?

时间:2016-05-10 05:29:08

标签: javafx media

我正在开展一个大学项目,我们被要求选择一个项目,所以我选择了教他们ABC的孩子。但是当我添加媒体时,我的项目突然崩溃,我试图找出原因,但这没用。

package project;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class Project extends Application {

    private String[] letters = {"A", "B", "C",
            "D", "E", "F", "G", "H",
            "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
            "S", "T", "U", "V", "W", "X", "Y", "Z"};

    private ImageView[] ImageViews = {
            new ImageView("a.jpg"),
            new ImageView("b.jpg"),
            new ImageView("c.jpg"),
            new ImageView("d.jpg"),
            new ImageView("e.jpg"),
            new ImageView("f.jpg"),
            new ImageView("g.jpg"),
            new ImageView("h.jpg"),
            new ImageView("i.jpg"),
            new ImageView("j.jpg"),
            new ImageView("k.jpg"),
            new ImageView("l.jpg"),
            new ImageView("m.jpg"),
            new ImageView("n.jpg"),
            new ImageView("o.jpg"),
            new ImageView("p.jpg"),
            new ImageView("q.jpg"),
            new ImageView("r.jpg"),
            new ImageView("s.jpg"),
            new ImageView("t.jpg"),
            new ImageView("u.jpg"),
            new ImageView("v.jpg"),
            new ImageView("w.jpg"),
            new ImageView("x.jpg"),
            new ImageView("y.jpg"),
            new ImageView("z.jpg")    
    };

    protected MediaView[] sound = {
            new MediaView(new MediaPlayer(new Media("a.mp3"))),
            new MediaView(new MediaPlayer(new Media("b.mp3"))),
            new MediaView(new MediaPlayer(new Media("c.mp3"))),
            new MediaView(new MediaPlayer(new Media("d.mp3"))),
            new MediaView(new MediaPlayer(new Media("e.mp3"))),
            new MediaView(new MediaPlayer(new Media("f.mp3"))),
            new MediaView(new MediaPlayer(new Media("g.mp3"))),
            new MediaView(new MediaPlayer(new Media("h.mp3"))),
            new MediaView(new MediaPlayer(new Media("i.mp3"))),
            new MediaView(new MediaPlayer(new Media("j.mp3"))),
            new MediaView(new MediaPlayer(new Media("k.mp3"))),
            new MediaView(new MediaPlayer(new Media("l.mp3"))),
            new MediaView(new MediaPlayer(new Media("m.mp3"))),
            new MediaView(new MediaPlayer(new Media("n.mp3"))),
            new MediaView(new MediaPlayer(new Media("o.mp3"))),
            new MediaView(new MediaPlayer(new Media("p.mp3"))),
            new MediaView(new MediaPlayer(new Media("q.mp3"))),
            new MediaView(new MediaPlayer(new Media("r.mp3"))),
            new MediaView(new MediaPlayer(new Media("s.mp3"))),
            new MediaView(new MediaPlayer(new Media("t.mp3"))),
            new MediaView(new MediaPlayer(new Media("u.mp3"))),
            new MediaView(new MediaPlayer(new Media("v.mp3"))),
            new MediaView(new MediaPlayer(new Media("w.mp3"))),
            new MediaView(new MediaPlayer(new Media("x.mp3"))),
            new MediaView(new MediaPlayer(new Media("y.mp3"))),
            new MediaView(new MediaPlayer(new Media("z.mp3")))
    };

    @Override

    public void start(Stage primaryStage) {
        ListView<String> l = new ListView<>
                (FXCollections.observableArrayList(letters));
        l.setPrefSize(300, 700);
        l.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        FlowPane imagePane = new FlowPane(20, 20);
        BorderPane pane = new BorderPane();
        pane.setLeft(new ScrollPane(l));
        pane.setCenter(imagePane);

        l.getSelectionModel().selectedItemProperty().addListener(
                ov -> {
                    imagePane.getChildren().clear();
                    for (Integer i : l.getSelectionModel().getSelectedIndices()) {
                        imagePane.getChildren().add(ImageViews[i]);
                    }
                });

        ListView<String> le = new ListView<>
                (FXCollections.observableArrayList(letters));
        le.setPrefSize(300, 700);
        le.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        FlowPane soundpane = new FlowPane(10, 10);
        pane.setCenter(soundpane);
        pane.setRight(new ScrollPane(le));

        l.getSelectionModel().selectedItemProperty().addListener(
                ov -> {
                    soundpane.getChildren().clear();
                    for (Integer i : l.getSelectionModel().getSelectedIndices()) {
                        soundpane.getChildren().add(sound[i]);
                    }
                });

        Scene scene = new Scene(pane, 500, 200);
        primaryStage.setTitle("Letters");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

1 个答案:

答案 0 :(得分:0)

我的猜测只是处理能力。尝试语音合成而不是26个音频文件