PortInUseException with Java and Duemilanove

Okay, so this is my code:

    public static CommPortIdentifier ArduinoSerial;
    public static CommPort arduino;

    public static void main(String[] args) {
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        while(portList.hasMoreElements()) {
                CommPortIdentifier serialId = (CommPortIdentifier) portList.nextElement();
                if(serialId.getName().equals("/dev/tty.usbserial-A9007VjP")) {
                    ArduinoSerial = serialId;
        try {arduino = ArduinoSerial.open("Test", 60000);} catch (PortInUseException ex) {
            System.out.println("Arduino port is in use.  Unable to open port");

The problem is, that I am getting a "PortInUseException" error from an unknown application. Further details: Mac OS X New to arduino, but want to use my own Java program, not Processing. I am using the rxtx package. I tried my program again, but after a restart, and it did the same thing. What else could it be? How can I find out?

What else do you have running on the mac? The Arduino IDE? Is the Serial Monitor window open? Can you upload sketches to the Arduino?

The answers are in order:

  • Nothing. It was just after a restart, so just Finder, and Netbeans.
  • I have it on there, but it wasn’t running.
  • No, because Arduino IDE wasn’t open.
  • With the Arduino IDE, I can.

Let’s see… I just ran it out of a Terminal window, and still nothing. Is there any way to see what has a hold of it?

EDIT: Nevermind, I found a website link. Basically, heres what I did:
Open Terminal, and cd until you get to the root directory by using the command “cd …”
Then, type “cd var”. Do a “sudo mkdir lock”, and type in you password. (If you don’t know how to do that, google “sudo”.) Then, navigate to that directory, by opening finder, clicking on your hard drive, so that you are at the root directory, and on the menu bar, click “go”, and then “go to folder” type in “var”, and press enter. Then, right-click on the “lock” folder, and click “get info”. At the bottom of the window that pops up, there is a lock. Click it, so it looks unlocked. You probably have to type in your password. Then, change the permissions, until it says that you can read and write.

EDIT2: The first program I just wrote uses a potentiometer, and graphs the value on screen. I would suggest this, to anyone reading this and trying to connect to your computer, as your first project. It was fairly easy to do, and only took about 5 minutes with only one potentiometer.