小编mac*_*ey7的帖子

JAVA不兼容的类型:无法将对象转换为我的类型

我试图通过在单独的线程上进行工作并返回所需的对象来对JavaFX中的GUI进行更改。但是,在完成工作和task.setOnSucceeded()之后,我尝试检索创建的对象并得到错误“不兼容的类型:对象无法转换为VideoScrollPane类型”。

我认为这与原始类型有关,因为它发生在侦听器中,但是四处查看后找不到我想要的建议。

任何可以散发出的光将不胜感激。

Task task = new Task<VideoScrollPane>() {
    VideoScrollPane vsp;
    @Override protected VideoScrollPane call() {
        try {
            System.out.print("thread...");

            ExecutorService executor = Executors.newCachedThreadPool();
            Future<VideoScrollPane> future = executor.submit(new Callable<VideoScrollPane>() {
                @Override public VideoScrollPane call() {
                    return new VideoScrollPane(mediaview, vboxCentre, username, project);
                }
            });

            vsp = future.get();
        } catch(Exception exception) { System.out.println(exception.getMessage()); }

        return vsp;
    }
};
new Thread(task).start();

task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
    @Override public void handle(WorkerStateEvent t) {
        System.out.println("complete");

        try {

            //where the problem occurs
            VideoScrollPane v = task.get();     

        } catch(Exception exception) …
Run Code Online (Sandbox Code Playgroud)

java javafx

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

javafx ×1