JavaFX工具包未初始化

JavaFX工具包未初始化,java,Java,我试图输入两个管理员用户名/密码,但出现了一个名为“java.lang.IllegalStateException:Toolkit not initialized”的错误。这个程序一直运行良好,直到我添加了JTextField的内容,我检查了大量的网站(Oracle、StackOverFlow等),都没有找到答案。我不认为我在任何地方的代码中都使用了JavaFX。提前感谢:) 完整的错误代码在底部 这是我的代码: import javax.swing.JOptionPane; import ja

我试图输入两个管理员用户名/密码,但出现了一个名为“java.lang.IllegalStateException:Toolkit not initialized”的错误。这个程序一直运行良好,直到我添加了JTextField的内容,我检查了大量的网站(Oracle、StackOverFlow等),都没有找到答案。我不认为我在任何地方的代码中都使用了JavaFX。提前感谢:) 完整的错误代码在底部

这是我的代码:

import javax.swing.JOptionPane;
import javax.swing.JTextField;
//import java.awt.*;
//import java.awt.event.*;
//import java.util.Scanner; Replaced with JOptionPane;
import java.util.concurrent.TimeUnit;
//import java.io.File;                 
//import java.io.FileWriter;
//import java.io.FileReader; //Needed for a previous version
//import java.io.IOException;
//import java.io.BufferedReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;   
import java.util.Date;
public class HackerGame {
public static void Credentials() throws InterruptedException {
    System.out.println('\u000C');
    String[] names = new String[]{"Hugh Jackman","David Lowe","Ethan Reed"};
    String[] usernames = new String[]{"HughMan13","BigDave13","Ethanol13"};
    String[] passwords = new String[]{"SmallMan31","SmallDave31","Diesel31"};
    System.out.println("Gathering Employee Information...");
    TimeUnit.SECONDS.sleep(3);
    System.out.println("Listing Employee Credentials: ");
    System.out.println(""); //Kept for distance purposes
    for (int i = 0; i < 3; i++) {
        System.out.println("Name: " + names[i] + " Username: " +
                            usernames[i] + " Password: " + passwords[i]);
        System.out.println("---");
        TimeUnit.SECONDS.sleep(1);
}
    TimeUnit.SECONDS.sleep(5);
}
public static void Growth() throws InterruptedException {
    int years = 2012;
    int value = 150000;
    System.out.println('\u000C');
    System.out.println("Company Growth By Year: ");
    for (int i = 0; i < 5; i++) {
        System.out.println("Year: " + (years + i) + " Value: " + "$" +
                            (value + (45000 * i)));
        System.out.println("---");
        TimeUnit.SECONDS.sleep(1);                    
    }
    TimeUnit.SECONDS.sleep(5);
}
public static void Console() throws InterruptedException {
    System.out.println('\u000C');
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    System.out.println("Accessing Console Log For: " + dateFormat.format(date) + " ...");
    TimeUnit.SECONDS.sleep(3);
    System.out.println("---------------");
    System.out.println("IP 153.131.132.64 Connected");
    System.out.println("IP 153.131.132.64 Opened /bin/users/admin/username.txt");
    System.out.println("IP 153.131.132.64 Closed /bin/users/admin/username.txt");
    System.out.println("IP 153.131.132.64 Opened /bin/users/admin/password.txt");
    System.out.println("IP 153.131.132.64 Closed /bin/users/admin/password.txt");
    System.out.println("IP 153.131.132.64 Cleared /bin/console/cache");
    System.out.println("IP 153.131.132.64 Disconnected");
    System.out.println("IP 233.132.104.140 Connected");
    System.out.println("IP 233.132.104.140 Opened /bin/console/cache");
    System.out.println("IP 233.132.104.140 Restored /bin/console/cache");
    System.out.println("IP 233.132.104.140 Copied /bin/console/cache");
    System.out.println("IP 233.132.104.140 Closed /bin/console/cache");
    System.out.println("IP 233.132.104.140 Disconnected");
    System.out.println("End of Log For: " + dateFormat.format(date));
    TimeUnit.SECONDS.sleep(5);
}
public static void main(String[] args) throws InterruptedException {
    System.out.println('\u000C');
    System.out.println("You are hacking into the system. Use these numbers to");
    System.out.println("help you: 33472001, 123, and 321. Good Luck.");
    System.out.println("");
    System.out.println("Loading Game...");
    TimeUnit.SECONDS.sleep(7);     
    String[] firewallpass = new String[]{"33472001","10027433","20013347"};
    String[] firewallreq = new String[3];
        firewallreq[0] = "Enter First FireWall Password: ";
        firewallreq[1] = "Enter Second FireWall Password: ";
        firewallreq[2] = "Enter Third FireWall Password: ";
    String[] database = new String[]{"Employee Credentials","Company Growth","Console Log"};
    System.out.println('\u000C');
    String input;
    input = JOptionPane.showInputDialog
                ("Launch Program? Y/N: ");
    if (input.equalsIgnoreCase("Y")) {
        System.out.println("Initializing...");
        TimeUnit.SECONDS.sleep(3);
        System.out.println('\u000C');
    } else if (input.equalsIgnoreCase("N")) {
        System.out.println("Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);            
    } else {
        System.out.println("Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);
    }
    for (int i = 0; i < 3; i++) {
    //System.out.println(firewallreq[i]);
    String firewall; 
    firewall = JOptionPane.showInputDialog(firewallreq[i]);
    System.out.println('\u000C');
    if (firewall.equals(firewallpass[i])) {
        System.out.println("Bypassing...");
        TimeUnit.SECONDS.sleep(3);
    } else {
        System.out.println("You have been blocked. Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);
    }
}
boolean adminLogIn = true;
while(adminLogIn) {
    System.out.println('\u000C');
    System.out.println("Enter Administrator Credentials: ");
    String adminusername = "admin";
    String adminpassword = "admin123";
    TimeUnit.SECONDS.sleep(1);

    JTextField username = new JTextField();      
    JTextField password = new JTextField();
    Object[] message = {
        "Username: ", username,
        "Password: ", password
    };
    int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
    if (option == JOptionPane.OK_OPTION) {
        if (username.getText().equals(adminusername) && password.getText().equals(adminpassword)) {
            System.out.println("Logging In...");
            TimeUnit.SECONDS.sleep(3);
            adminLogIn = false;
        } else {
            System.out.println("Wrong username/password. Try Again");
    }
}
}
    System.out.println('\u000C');
    boolean loggedIn = true;
    while(loggedIn) {
    System.out.println("Enter Q to logout");
    System.out.println("You have access to these databases: ");
    System.out.println("----------");
    for (int i = 0; i < 3; i++) {
        System.out.println(database[i]);
        System.out.println("----------");
        TimeUnit.SECONDS.sleep(1);
}
    boolean methodChoice = true;
    while(methodChoice) {
        String method;
    method = JOptionPane.showInputDialog("Enter A Method: ");
if (method.equalsIgnoreCase(database[0])) {
    Credentials();
    methodChoice = false;
} else if (method.equalsIgnoreCase(database[1])) {
    Growth();
    methodChoice = false;
} else if (method.equalsIgnoreCase(database[2])) {
    Console();
    methodChoice = false;
} else if (method.equalsIgnoreCase("Q")) {
    System.out.println("Logging Out...");
    TimeUnit.SECONDS.sleep(3);
    System.exit(0);
} else {
    System.out.println("Enter A Valid Inquiry.");
}
}
}
}
}

所以问题是我使用的应用程序BlueJ在某种程度上被破坏了,我无法运行我的任何程序。重新下载并删除损坏的程序修复了此问题。谢谢大家的帮助:)

我运行了你的程序,没有发生错误。可能提供异常的完整堆栈跟踪能否添加有问题的堆栈跟踪?Swing构造函数和方法只能从AWT事件调度线程调用。当你违反规则时,你会有不可预知的行为。这就是为什么它适用于其他人,但不适用于你。用于在正确的线程上运行Swing代码。@Piro我已在bottom@coder-croc我在底部添加了完整的错误
"java.lang.IllegalStateException: Toolkit not initialized"
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)
at bluej.runtime.ExecServer.runOnTargetThread(ExecServer.java:902)
at bluej.runtime.ExecServer.access$700(ExecServer.java:78)
at bluej.runtime.ExecServer$3.run(ExecServer.java:767)