Note that there are some explanatory texts on larger screens.

plurals
  1. POHashMap.put causing an infinite loop in Java
    primarykey
    data
    text
    <p>So I have a class named MainControl that is ran from another class (The main one) that I am certain only runs once. Inside of MainControl I have a few things that have to be loaded, one of which being a function that populates the HashMap with the key set to the keybind (int) and the values set to a class that holds the information of the specific keybinds function (KeyDetails).</p> <p>So to populate the hashmap it goes through 2 loops, the first being to loop through the list of functions, the second to check if the key should be bound to the function. If the second loop finds that it should be bound it will run Keybinds.put(KeyCode, new Details(Function, KeyCode, KeyName, false); (Just ignore the false).</p> <p>For some reason it ends up forcing MainControl(); to run again once it reached Keybinds.put... for no reason at all. There are no functions that should cause MainControl to run and it works when I remove the Keybinds.put line. Just by removing THAT single line it works. </p> <pre><code>public MainControl() { System.out.println("Starting System"); LoadSession("Default"); System.out.println("Ended System - Never Reached"); } public static void LoadSession(String s) { Keybinds = new HashMap(); for (int i = 0; i &lt; FunctionStringList.length; i++) { String Key = ""; int KeyVal = 0; try { for (int a = 0; a &lt; KeyBindingList.length; a++) { if (KeyBindingList[a].KeyName.equalsIgnoreCase(FunctionStringList[i])) { Key = KeyBindingList[a].KeyName KeyVal = KeyBindingList[a].KeyCode } } Keybinds.put(KeyVal, new Details(FunctionStringList[i], KeyVal, Key, false)); System.out.println("Key: " + Key + " Val: " + KeyVal + " Hack: " + FunctionStringList[i]); } catch (Exception E) { E.printStackTrace(); } } } public static String FunctionStringList[] = { "Forward", "Backwards", "StrafeLeft", "StrafeRight", "Jump", "Sneak" }; </code></pre> <p>Details Class:</p> <pre><code>public class Details extends MainControl { public Details(String Name, int KeyCode, String KeyName2, boolean Bool) { FunctionName = Name; Code = KeyCode; KeyName = KeyName2 != null ? KeyName2 : "None"; State = Bool; } public boolean Toggle() { State = !State; return State; } public void SendChat(String s) { Console.AddChat(s); } public String FunctionName; public String KeyName; public int Code; public boolean State; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload