PCTools NXJDataViewer modification

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

PCTools NXJDataViewer modification

Postby AlanB » Mon Oct 10, 2011 3:08 pm

Hi, I wanted to create a modified NXJDataViewer such that the data is also saved to a text.file on the PC. So I copied the NXJDataViewer.java to my experimental package and changed the class name (to fileNXJData) and updated the imports. For the first test I didn´t change any code, so I expected it to run exactly as the original does. It compiled okay but when run it gives an exception error when the connect-button on the UI-window is pressed. The error is as follows:
    Connecting to
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.microedition.io.Connector$1 cannot be cast to javax.microedition.io.StreamConnection
    at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:120)
    at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:228)
    at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:51)
    at lejos.pc.tools.DataViewComms.connectTo(DataViewComms.java:42)
    at lejos.pc.tools.DataViewComms.connecTo(DataViewComms.java:35)
    at fileReadersAndWriters.fileNXJData.actionPerformed(fileNXJData.java:126)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

The fileNXJData.java code snippet around line 126 is as follows:
Code: Select all
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == connectButton)
        {
            String name = nameField.getText();
            String address = addrField.getText();
            boolean useUSB = usbButton.isSelected();
           
            if (!comm.connecTo(name, address, useUSB))
            {
                setStatus("Connect Failed");
                if (useUSB)
                {
                    JOptionPane.showMessageDialog(this, "Sorry... but USB did not connect.\n" +
                            "You might want to check:\n " +
                            " Is the NXT turned on and connected? \n " +
                            " Does it display  'wait for USB'? ", "We have a connection problem.",
                            JOptionPane.PLAIN_MESSAGE);

                } else
                {
                    JOptionPane.showMessageDialog(this, "Sorry... Bluetooth did not connect. \n" +
                            "You might want to check:\n" +
                            " Is the dongle plugged in?\n" +
                            " Is the NXT turned on?\n" +
                            " Does it display  'wait for BT'? ",
                            "We have a connection problem.",
                            JOptionPane.PLAIN_MESSAGE);
                }
            }
        } else if (e.getSource() == startButton)
        {
           theLog.setText("");
            _rowLength = Integer.parseInt(lengthField.getText());
            _recordCount = 0;
            comm.startDownload();
        }
    }


To check I moved my class fileNXJData to the original pctools/lejos.pc.tools package and there it runs okay. Can anyone advise as to what I am doing wrong, thanks.
I am using a PC with Windows7, JDK 1.7, Eclipse 1.4.0.20110615-0550, leJOS plug-in 0.9.0.201106192010.

Regards AlanB
AlanB
New User
 
Posts: 4
Joined: Sat Jul 16, 2011 12:37 pm

Re: PCTools NXJDataViewer modification

Postby kirkpthompson » Mon Oct 10, 2011 7:17 pm

Hi AlanB.

To check I moved my class fileNXJData to the original pctools/lejos.pc.tools package and there it runs okay. Can anyone advise as to what I am doing wrong, thanks.

That sort of sounds like a classpath (or a similar name/class resolution) problem to me.

FYI, we have a new datalogging infrastructure in the development snapshot [hasn't been released yet] if you feel confident/brave to "go there" and use the dev snapshot. Bear in mind that it may not be stable and classes, methods, etc. may not be the same as what you're used to in an official [previous] release.

The project is at http://lejos.svn.sourceforge.net/viewvc/lejos/trunk/org.lejos.charting/. A thread that may be of interest is http://lejos.sourceforge.net/forum/viewtopic.php?f=5&t=466. I sort of hijacked it so the related posts are towards the end.

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: PCTools NXJDataViewer modification

Postby skoehler » Fri Oct 14, 2011 11:25 am

AlanB wrote:Hi, I wanted to create a modified NXJDataViewer such that the data is also saved to a text.file on the PC. So I copied the NXJDataViewer.java to my experimental package and changed the class name (to fileNXJData) and updated the imports. For the first test I didn´t change any code, so I expected it to run exactly as the original does. It compiled okay but when run it gives an exception error when the connect-button on the UI-window is pressed. The error is as follows:
    Connecting to
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.microedition.io.Connector$1 cannot be cast to javax.microedition.io.StreamConnection
    at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:120)
    at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:228)
    at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:51)
    at lejos.pc.tools.DataViewComms.connectTo(DataViewComms.java:42)
    at lejos.pc.tools.DataViewComms.connecTo(DataViewComms.java:35)
    at fileReadersAndWriters.fileNXJData.actionPerformed(fileNXJData.java:126)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

The fileNXJData.java code snippet around line 126 is as follows:


From the stack trace, you can conclude that fileNXJData has nothing to with it. The error is in NXTCommBluecove.java, line 120. However, the error is kind of mysterious.
I would start with checking, which of JAR files that is in the classpath of your project contains javax.microedition.io.Connector and which contains javax.microedition.io.StreamConnection. Also, I'm curious which JAR contains javax.microedition.io.Connector$1, because it's not part of the bluecove.jar that comes with leJOS.
skoehler
leJOS Team Member
 
Posts: 1458
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 3 guests

cron
more stuff