java shutdown hook "system cannot find message text"

230 views Asked by At

I have the following shutdown hook in the main method of my Server class:

Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
        if (open) {
            open = false;

            //log out all players
            System.out.println("Logging out all players...");
            Iterator playerIterator = playerList.values().iterator();
            while (playerIterator.hasNext()) {
                Player p = (Player) playerIterator.next();
                playerIterator.remove();
                p.logout("The server has been shut down.");
            }

            //save the World
            System.out.println("Saving world...");
            try {
                String worldFile = Server.path.concat("/worlds/"+worldName);
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(worldFile));
                out.writeObject(world);
            } catch (FileNotFoundException fe) {
                System.out.println("World \"" + worldName + "\" couldn't be saved properly - world file not found.");
                fe.printStackTrace();
            } catch (IOException ioe) {
                System.out.println("I/O error while attempting to save world \"" + worldName + "\".");
                ioe.printStackTrace();
            }

            //close Server socket
            try {
                serverSocket.close();
                System.out.println(worldName + " is now closed.");
            } catch (IOException ioe) {
                System.out.println("Failed to close ServerSocket.");
                ioe.printStackTrace();
            }
        }
    }
});

When I stop the server (by pressing Ctrl+c), the shutdown hook does everything it's supposed to do (it works perfectly), but I get the following message and the server won't finish shutting down (I have to press Ctrl+c again):

The system cannot find message text for message number 0x237b in the message file for Application.

I don't think it used to do this before I updated to Java 7! Any ideas why it might be doing this?

1

There are 1 answers

0
bumbleshoot On

Found the answer at: http://social.technet.microsoft.com/Forums/windows/en-US/2d506b96-e856-4752-90af-4f8194bb0040/windows-7-command-prompt-message-errors-cmdexe?forum=w7itprogeneral

You're getting those messages because you're running the CMD.exe from a folder different than what's defined in the %COMSPEC% environment variable.

If you want to open a command prompt to a specific folder you can right-click and pick "Open Command Window Here" (built into Vista and 7). It's extra slick because if you do it on a network share Windows will automatically map a drive letter to it for you. Right-click on the folder C:\windows\system32 on your machine while holding down the shift key. You'll see an extra context-sensitive menu item there: Open Command Prompt here. Just click on this menu and a command window will open with the current working directory set to the folder's actual location.

Another option is to make a new CMD shortcut.

Make a new shortcut, enter %COMSPEC% as the Target, and give it a name you'd like. Once it's created, edit the shortcut and change the "Start in" path to where you'd like the command prompt to open to.