-1
안녕하세요. 저는이 예제를 실행하기 위해 밤새도록 노력해 왔으며 행운이 없었습니다. 솔루션을 찾을 수 없습니다. 두 파일이 있습니다.간단한 작업 예제를 실행
먼저 다음은 내가하지만 매우 뭔가를 잘못하고 있어요 알고 IteratingTask.java 파일과 그 내용
//import javafx.concurrent.Task;
import javafx.application.Application;
import javafx.concurrent.Task;
/**
*
* @author brett
*/
public class IteratingTask extends Task<Integer> {
private final int totalIterations;
public IteratingTask(int totalIterations) {
this.totalIterations = totalIterations;
}
@Override protected Integer call() throws Exception {
int iterations;
// iterations = 0;
for (iterations = 0; iterations < totalIterations; iterations++) {
if (isCancelled()) {
updateMessage("Cancelled");
break;
}
updateMessage("Iteration " + iterations);
updateProgress(iterations, totalIterations);
}
return iterations;
}
}
입니다 여기에 그 내용
import javafx.application.Application;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author brett
*/
public class Worker {
/**
* @param args the command line arguments
* @throws java.lang.Exception
*/
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
doit();
}
private static void doit(){
try {
IteratingTask mytask = new IteratingTask(800000);
mytask.call();
System.out.println(mytask.getValue());
int pro = (int) mytask.getProgress();
System.out.println(pro);
} catch (Exception ex) {
Logger.getLogger(Worker.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Worker.java입니다 .. 나는 그것을 볼 수 없다. 여기에 어떤 조언이 좋지 않을까 ....이
run:
Jan 31, 2015 11:56:38 PM Worker doit
SEVERE: null
java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:270)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:265)
at javafx.application.Platform.runLater(Platform.java:81)
at javafx.concurrent.Task.runLater(Task.java:1211)
at javafx.concurrent.Task.updateMessage(Task.java:1129)
at IteratingTask.call(IteratingTask.java:24)
at Worker.doit(Worker.java:38)
at Worker.main(Worker.java:31)
BUILD SUCCESSFUL (total time: 0 seconds)
그것은 확인 빌드를 얻을 오류입니다.
을 그리고 ..what이 스윙 * 또는 관계 되는가 :
또한, 다음과 같이,이 실행하는 동안,
Task
의는 일반적으로 백그라운드 스레드에서 실행하도록 구성되어 있습니다 IDE? 코드가 Java FX 기반 (** Swing에 대한 ** 툴킷 **) 인 것 같아서 IDE가 자동으로 문제를 해결하려고하거나 (현재 코드가 실패했음을) 의심 스럽습니다. –미안하지만, 나는 배우려고 노력하고 있고, 나의 이해는 여전히 매우 원시적이다. – Brett