java.lang.IllegalStateException:不能多次调用应用程序启动 - JavaFX(第一次工作,第二次工作)

时间:2016-08-01 20:51:58

标签: java javafx platform

首先,我为英语道歉... lol

第一次运行流程生成图表时,运行顺利,但第二次启动时,会显示错误:“java.lang.IllegalStateException:不能多次调用应用程序启动”

帮助我,我不知道该怎么做才能工作。

申请代码:

package reports;

import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import javax.imageio.ImageIO;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import models.dao.ReportDAO;
import models.dto.ReportHarvestersTimeManagmentDTO;

public class ReportPerfCompHarvTime extends Application {

    private ReportDAO reportDAO = new ReportDAO();
    private String folder;
    private String chartName;

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

    public void run(String pFolder, String pChartName) throws Throwable {
        this.folder = pFolder;
        this.chartName = pChartName;
        launch();
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public void start (Stage stage) {
        try {
            // Stage stg = new Stage();
            // stage.setTitle("GESTÃO DO TEMPO (%)");

            Platform.setImplicitExit(false);

            NumberAxis xAxis = new NumberAxis();
            CategoryAxis yAxis = new CategoryAxis();
            BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis);

            // bc.setTitle("GESTÃO DO TEMPO (%)");
            xAxis.setTickLabelRotation(90);
            yAxis.setLabel("Frente");

            List<ReportHarvestersTimeManagmentDTO> listReport = reportDAO.lstReportHarvestersTimeManagmentDTO();

            BigDecimal value = new BigDecimal(0);
            BigDecimal value100 = new BigDecimal(100);
            XYChart.Series series = new XYChart.Series();

            for (ReportHarvestersTimeManagmentDTO lst : listReport) {
                series.setName(lst.getActivityName());
                if (lst.getWorkedHours().compareTo(BigDecimal.ZERO) > 0) {
                    value = new BigDecimal(0);
                    value = lst.getTimeManagmentHours().divide(lst.getWorkedHours(), 2, RoundingMode.HALF_UP);
                    value = value.multiply(value100);
                    series.getData().add(new XYChart.Data(value.doubleValue(), lst.getWorkfrontID().toString()));
                }
            }

            bc.getData().add(series);

            bc.setAnimated(false);
            bc.applyCss();
            bc.layout();

            Scene scene = new Scene(bc, 800, 600);
            stage.setScene(scene);
            stage.show();

            WritableImage image = bc.snapshot(new SnapshotParameters(), null);
            File file = new File(this.folder + this.chartName + ".png");
            ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);

        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
            stage.close();
            Platform.exit();
        }
    }

}

0 个答案:

没有答案