I am trying to update a ProgressBar
that is added to a separate Stage in javafx
. I have defined task in a method named messagemerge()
and a new thread containing this task is called from there. Each time i try to use the task that is returned by the method messagemerge()
to the main, it throws a NullPointerException
This is what i have tried
ProgressBarDialog progressBarDialog=new ProgressBarDialog();
Task<Void> task=messageMerge();
progressBarDialog.progressBar.progressProperty().bind(task.progressProperty());
The above code is written in the main
The method messageMerge()
is as defined below
public Task<Void> messageMerge() throws Exception
{
task=new Task<Void>(){
protected Void call()throws Exception{
for(i=0;i<50;i++)
updateProgress(i,50);
}
return null;
};
Thread thread=new Thread(task);
thread.start();
return task;
}
The progessBarDialog
is another class defined as below
public class ProgressBarDialog {
public ProgressBar progressBar=null;
public ProgressBarDialog()
{
Stage progressDialog=new Stage();
progressDialog.initModality(Modality.APPLICATION_MODAL);
ProgressBar progressBar=new ProgressBar();
progressBar.setProgress(0);
BorderPane progressPane=new BorderPane();
progressPane.setCenter(progressBar);
progressDialog.setScene(new Scene(progressPane,500,100));
progressDialog.show();
}
NullPointerException
occurs when i try to access task.progressProperty()
from the main. Could someone please help me on this. Any help is appreciated.