What does this error mean?

5 replies [Last post]
deepblue's picture
Joined: 01/06/2011

So here I am again, spending hours on the most mundane task.
What does this error mean?
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Provider may only be changed before input is created!
        at com.jme.input.MouseInput.setProvider(MouseInput.java:107)
        at env3d.Env.<init>(Env.java:137)
        at env3d.Env.<init>(Env.java:123)
        at Game.play(Game.java:47)
        at Game.gameRestart(Game.java:110)
        at UI$2.actionPerformed(UI.java:33)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6267)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6032)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Joined: 12/13/2010
I need to see your code, and

I need to see your code, and need to know what you are trying to do.
I'm guessing that you are trying to reset your game?  In this case, do NOT re-create the env object.  So bascially, leave out the "Env env = new Env()" line when restarting the game.

deepblue's picture
Joined: 01/06/2011
So basically, we just restart

So basically, we just restart the while-loop and not the entire play() method? I've done some research on restarting while loops and everyone says to put another while loop around it and create another boolean, and I tried putting a while-loop around everything except "Env env = new Env()". That didn't work.

KMacKenzie's picture
Joined: 12/10/2010
If you are trying to setup a

If you are trying to setup a method to reset your game by pressing a key, here is how:
Take everything out of your constructor and play method before the while loop that is used to setup your game (everything except Env env = new env()).
Put it into a method called setup() and then just call that method (remember to maintain the necessary order of creation, you may have some compiling errors if you change the order. Also, if you get a 'NULL POINTER ERROR" you probably need to declair a field before the constructor, if this happens and you dont know how to fix it copy and paste your code here and ill help you find the problem.
Once all these things are in a setup() method then you can just call that method anytime you want, once at the beginning of the play() method and then again in the while loop while a key is pressed.
Its best to just not mess around with the while loop at all, that should basically never stop looping as long as your game is running.
Let me know if any of this didn't make sense to you or im not even answering your question, because I dont really know what your working on right now so I may be trying to answer the wrong question.

KMacKenzie's picture
Joined: 12/10/2010
Here is an example of an

Here is an example of an excerpt of one of my game classes and what im talking about.
 * A predator and prey simulation.  Fox is the predator and Tux is the prey.
public class Game extends EnvApplet
    private Env env;    
    private boolean finished;
    private Room room;
    private ArrayList<Creature> creatures, dead_creatures, new_creatures;
    private int hcap, k;
    private double sfox, stux;
    private Ball b;
    private double camX,camY,camZ;
    private int cam;
    private boolean fs;
     * Constructor for the Game class. It sets up the foxes and tuxes. NOTICE CONSTRUCTOR EMPTEY
    public Game()
     * Play the game
    public void play()
        finished = false;
        // Create the new environment.  Must be done in the same
        // method as the game loop
        env = new Env();
        // The main game loop
        while (!finished) {            
            // Gather the user input
            int key = env.getKey();
            // Move each fox and tux.
            for (Creature c : creatures) {
                c.move(creatures, dead_creatures, new_creatures, room.getBlocks(), hcap, sfox, stux, k);
            // Clean up of the dead tuxes.
            for (Creature c : dead_creatures) {
            // we clear the ArrayList for the next loop.  We could create a new one 
            // every loop but that would be very inefficient.
            for (Creature c : new_creatures) {
            // Terminate program when user press escape
            if (key == Keyboard.KEY_ESCAPE) {
                finished = true;
            } else if (env.getKeyDown(Keyboard.KEY_UP)) {
            if (env.getKeyDown(Keyboard.KEY_LEFT)) {
            } else if (env.getKeyDown(Keyboard.KEY_RIGHT)) {
            if (key == Keyboard.KEY_SPACE) {
                if (!b.getFalling() && !b.getJumping()) {
            if (env.getKeyDown(Keyboard.KEY_N)) {
            if (env.getKeyDown(Keyboard.KEY_F)) {
                fs = !fs;
            if (env.getKey() == Keyboard.KEY_C) {
                if (cam == 1) {
                    cam = 2;
                } else if (cam == 2) {
                    cam = 3;
                } else if (cam == 3) {
                    cam = 1;
            if (cam == 1) {
            } else if (cam == 2) {
            } else if (cam == 3) {
            b.move(creatures, dead_creatures, room.getBlocks());
            String str3 = "Camera: "+cam;
            addDisplayStr("Stop the Foxes from eating the Tuxes by running into them!",20,460,1);
            addDisplayStr("Lose if all tuxes are eaten or foxes grow to over 100",40,440,1);
            addDisplayStr("Win by eating all the foxes",160,420,1);
            addDisplayStr("Press 'N' to reset",420,20,1);
            // Update the environment
        // Just a little clean up
     * Sets up the Env3d environment, used for starting the game and reseting it
    private void setup() {
        hcap = 20000;
        sfox = 0.85;
        stux = 0.99;
        k = 5;
        cam = 2;
        fs = false;
        room = new Room();
        b = new Ball(25,1,25,room,env);
        // we use a separate ArrayList to keep track of each animal. 
        // our room is 50 x 50.
        for (int i = 0; i < 10; i++) {
            room.addBlock(new Block((int)(Math.random()*194)+1, 1, (int)(Math.random()*44)+1));     
        creatures = new ArrayList<Creature>();
        for (int i = 0; i < 55; i++) {
            if (i < 5) {
                creatures.add(new Fox(((int)(Math.random()*20)+477), 1, (int)(Math.random()*48)+1));        
            } else {
                creatures.add(new Tux((int)(Math.random()*20)+1, 1, (int)(Math.random()*48)+1));
        // Make the room 50 x 50.
        for (Block block : room.getBlocks()) {
        // Add all the animals into to the environment for display
        for (Creature c : creatures) {
        // Turn off the default controls
        // A list to keep track of dead creatures.
        dead_creatures = new ArrayList<Creature>();
        // A list to keep track of new creatures.
        new_creatures = new ArrayList<Creature>();

deepblue's picture
Joined: 01/06/2011
Ah, thanks Kenny. While at my

Ah, thanks Kenny. While at my monotonous job I was thinking about solving this and something very similar to this came to mind (just re-initializing the objects) and seeing an example made it crystal clear.