Ben A
Ben A

Reputation: 799

JavaFX ToolKit Not Initialized

I'm trying to have two inputs for an admin username/password, but an error by the name of "java.lang.IllegalStateException: Toolkit not initialized". This program was working fine until I added the JTextField stuff, and I checked a ton of websites (Oracle, StackOverFlow, etc), and couldn't find an answer. I don't think I'm using JavaFX in my code anywhere. Thanks in advance :) The full error code is at the bottom.

This is my code:

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.");
}
}
}
}
}

And this is the exception

"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)

Upvotes: 1

Views: 1911

Answers (1)

Ben A
Ben A

Reputation: 799

So the problem was that the application I was using, BlueJ, was corrupted in some way in that I wouldn't be able to run any of my programs. Re-Downloading and deleting the corrupted program fixed this issue. Thanks everyone for the help :)

Upvotes: 2

Related Questions