I have a javaFx application that works no problem at all when I run the main method from Eclipse. However when I convert the application into an executable .jar and run the .jar when I click the button that uses FileChoose to select a file i get this error.
"Exception in thread "Thread-20" java.lang.IllegalStateException: Thisoperation is permitted on the event thread only; currentThread = Thread-20"
Here is the code that I have and again this code works great when I run the application from eclipse, just not when its converted to a .jar. I used eclipse to convert the application to a jar.
public void uploadMessagesButtonActionPerformed(ActionEvent event) {
if(uploadCSVThread.isAlive()) {
uploadCSVThread.interrupt();
try {
uploadCSVThread.join();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
uploadCSVThread = new Thread() {
public void run() {
Platform.runLater( new Runnable() {
public void run() {
loader.setProgress(0.0);
loader.setVisible(true);
}
});
FileChooser currUploadFile = new FileChooser();
File selectedFile = currUploadFile.showOpenDialog(null);
if(selectedFile != null) {
System.out.println(selectedFile.getPath());
try {
FileReader currRdr = new FileReader(selectedFile);
CSVReader currReader = new CSVReader(currRdr);
final ArrayList<String[]> listOfMessages = (ArrayList<String[]>) currReader.readAll();
for(int i = 0; i < listOfMessages.size(); i++) {
final int x = i;
String[] shipmentMessages = listOfMessages.get(i);
//String[] shipmentMessages = currReader.readNext();
//while(shipmentMessages != null) {
/*for(int i = 0; i < shipmentMessages.length; i++) {
System.out.println("shipmentMessages -> " + shipmentMessages[i]);
}*/
Map<String, String> headers = createHeaderMapFromHeaderString(shipmentMessages[0], "\n");
String body = shipmentMessages[1];
shipmentMessages = currReader.readNext();
try {
/*ObjectName queue = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + currentBrokerName
+ ",destinationType=Queue,destinationName=" + VM_AND_DIRECTVM_Q);*/
//headers.put("TO_DESTINATION", returnSelectedEndpoints());
QueueViewMBean queueView = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(conn,
currentQueue,
QueueViewMBean.class,
true);
queueView.sendTextMessage(headers, body, serverLookUp.serverUserNameLookUp(currentServer), serverLookUp.serverPasswordLookUp(currentServer));
Platform.runLater( new Runnable() {
public void run() {
loader.setProgress((double)x/(double)listOfMessages.size());
}
});
} catch (MalformedObjectNameException e) {
logger.error(e);
}
}
updateQueueInList(currentQueue, currentQueueIndx, true);
readQueue(conn, currentQueue);
loader.setVisible(false);
} catch (Exception e) {
messageCouldntSendPopUpBox.setVisible(true);
logger.error(e);
}
}
loader.setVisible(false);
}
};
uploadCSVThread.start();
}