gpt4 book ai didi

java - 应用程序转换为 .jar 时 FileChooser 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:28 28 4
gpt4 key购买 nike

我有一个 javaFx 应用程序,当我从 Eclipse 运行 main 方法时,它运行完全没有问题。但是,当我将应用程序转换为可执行 .jar 并在单击使用 FileChoose 选择文件的按钮时运行 .jar 时,我收到此错误。

“线程“Thread-20”中出现异常 java.lang.IllegalStateException:仅在事件线程上允许此操作;currentThread = Thread-20”

这是我的代码,当我从 Eclipse 运行应用程序时,该代码运行得很好,但在转换为 .jar 时却不行。我使用 eclipse 将应用程序转换为 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();
}

最佳答案

有点长,所以很高兴回答。我误读了你的牙套;它肯定在它自己的线程中。我会在您的捕获中添加一些 e.printStackTrace() 来准确查找您遇到错误的位置。您的方法调用之一似乎在线程体内无效。如果您找到该位置但仍然无法弄清楚,请更新您的帖子以告知我们。否则,您可能需要考虑使用 Task 对象.

关于java - 应用程序转换为 .jar 时 FileChooser 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38209977/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com