Bluetooth + startProgram()

Post your NXJ projects, project ideas, etc here!

Moderators: roger, imaqine, 99jonathan

New User
Posts: 1
Joined: Thu Oct 27, 2011 5:35 pm

Bluetooth + startProgram()

Postby mindstormer1 » Fri Oct 28, 2011 11:12 am

Hello all,

I'm trying to start a program with a bluetooth connection, but i'm having some troubles because the bluetooth connection is closed when the program starts.
Does anyone knows how I could re-establish the bluetooth connection?

I use the following code:

Code: Select all

private NXTCommand nxtCommand = new NXTCommand();
private boolean connected;
private NXTComm nxtComm;

//Connect button
jButton1.addMouseListener(new MouseAdapter() {
   public void mousePressed(MouseEvent e) {
      try {
         NXTInfo nxtInfo = new NXTInfo(NXTCommFactory.BLUETOOTH, "NXT", "00:16:53:09:16:BF");
         NXTComm nxtComm = NXTCommFactory.createNXTComm(nxtInfo.protocol);
         connected =, NXTComm.LCP);

      } catch (NXTCommException ex) {
         Logger.getLogger(RemoteNXTView.class.getName()).log(Level.SEVERE, null, ex);

      //If the connection fails
         jLabel3.setText("Connection problem!");
      //If the connection is succefull
         try {
         } catch (IOException ex) {
            Logger.getLogger(RemoteNXTView.class.getName()).log(Level.SEVERE, null, ex);
            jLabel4.setText("Couldn't open file!");
         //Re-establish the bluetooth connection

Many thanks in advance!!

User avatar
leJOS Team Member
Posts: 305
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Bluetooth + startProgram()

Postby kirkpthompson » Fri Oct 28, 2011 1:35 pm

Well, the first thing I see is

Code: Select all

private NXTCommand nxtCommand = new NXTCommand();
doesn't provide a NXTCommRequest object in the constructor. What version are you using?

The next thing (assuming the above is not a problem) I see is you try to establish a new connection for every mouse button press. Why?

Leg Godt!

Return to “NXJ Projects”

Who is online

Users browsing this forum: No registered users and 0 guests