April 27, 20169 yr // Create a select box for tree options JComboBox<String> treeSelector = new JComboBox<>(new String[]{"Tree", "Oak"}); // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection. treeSelector.addActionListener(e -> selectedTree = treeSelector.getSelectedItem().toString()); I was using this code, but if I choose 'Tree' the client crashes, well, the CPU goes to 100% and I have to force quit, but if I choose 'Oak' then it works perfectly fine. I added another option in front of 'Tree' and now 'Tree' works in second position but the 'Oak' options is now causing the problem.
April 27, 20169 yr So line 56 in MainHandler.java is treeSelector.addActionListener(e -> selectedTree = treeSelector.getSelectedItem().toString()); ?
April 27, 20169 yr // Create a select box for tree options JComboBox<String> treeSelector = new JComboBox<>(new String[]{"Tree", "Oak"}); // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection. treeSelector.addActionListener(e -> selectedTree = treeSelector.getSelectedItem().toString()); I was using this code, but if I choose 'Tree' the client crashes, well, the CPU goes to 100% and I have to force quit, but if I choose 'Oak' then it works perfectly fine. I added another option in front of 'Tree' and now 'Tree' works in second position but the 'Oak' options is now causing the problem. Probably something else in your code. You should really learn what a NullPointerException is though... Edited April 27, 20169 yr by Explv
April 27, 20169 yr Author So line 56 in MainHandler.java is treeSelector.addActionListener(e -> selectedTree = treeSelector.getSelectedItem().toString()); ? Line 56: status = state.toString(); That other is on line 163.
April 27, 20169 yr Line 56: status = state.toString(); That other is on line 163. Well that is where your error is then.. Not the GUI. Pls learn how 2 debug pls pls
April 27, 20169 yr Line 56: status = state.toString(); That other is on line 163. You might want to post the whole code as what you posted does not raise any exception Your state variable is definately null though.
April 27, 20169 yr Line 56: status = state.toString(); That other is on line 163. You probably haven't initialised 'state' Programming 101 pls pls
April 27, 20169 yr Author You probably haven't initialised 'state' Programming 101 pls pls http://pastebin.com/khgk46f9
April 27, 20169 yr http://pastebin.com/khgk46f9 Edited from original comment. Pls learn Java. Why are you doing this in onLoop ?: switch (state) { case CHOP: new Chop(this); break; case DROP: new Drop(this); break; case IN_COMBAT: new InCombat(this); default: break; } Edited April 27, 20169 yr by Explv
April 27, 20169 yr Edited from original comment. Pls learn Java. Why are you doing this in onLoop ?: switch (state) { case CHOP: new Chop(this); break; case DROP: new Drop(this); break; case IN_COMBAT: new InCombat(this); default: break; } Thank I managed to get it working now. It might work but you are still doing a lot of things incorrectly
April 27, 20169 yr Author It might work but you are still doing a lot of things incorrectly Isn't it suppose to be in OnLoop()?
April 27, 20169 yr Isn't it suppose to be in OnLoop()? You are creating new instances of those actions every loop ... Should only create one instance of it, best way to do this is in the onStart() method.. After that you can actually run those instances int he onLoop
Create an account or sign in to comment