/** * Receive data from another NXT, a PC, a phone, * or another bluetooth device. * * Waits for a connection, receives an int and returns * its negative as a reply, 100 times, and then closes * the connection, and waits for a new one. * * @author Lawrie Griffiths * */public class BTReceive {

/** * This is a PC sample. It connects to the NXT, and then * sends an integer and waits for a reply, 100 times. * * Compile this program with javac (not nxjc), and run it * with java. * * You need pccomm.jar and bluecove.jar on the CLASSPATH. * On Linux, you will also need bluecove-gpl.jar on the CLASSPATH. * * Run the program by: * * java BTSend * * Your NXT should be running a sample such as BTReceive or * SignalTest. Run the NXT program first until it is * waiting for a connection, and then run the PC program. * * @author Lawrie Griffiths * */public class BTSend { public static void main(String[] args) { NXTConnector conn = new NXTConnector();

Exception in thread "main" java.lang.ClassCastException: javax.microedition.io.Connector$1 cannot be cast to javax.microedition.io.StreamConnection at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:129) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:280) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:239) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:347) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:362) at org.lejos.pcsample.btsend.BTSend.main(BTSend.java:50)

Hi,I've moved your question to a more appropriate section. Have you read the new user sticky?viewtopic.php?f=7&t=232In particular this part:

Make sure you provide details of the version of leJOS, what host system (windows, linux. Mac) you are using and what version of the operating system.

In this case we also need details of what version of Java you are trying to use and also how you have compiled and run the sample. Have you included the blucove.jar file included with leJOS in your classpath?

Do you already have Bluetooth setup and working? Are you able to run the standard leJOS tool nxjbrowse over Bluetooth from your PC to your NXT? If not I would make sure that you can get this working first, it uses the same classes as the samples and will check that your system is working properly.

gloomyandy wrote:Hi,I've moved your question to a more appropriate section. Have you read the new user sticky?viewtopic.php?f=7&t=232In particular this part:

Make sure you provide details of the version of leJOS, what host system (windows, linux. Mac) you are using and what version of the operating system.

In this case we also need details of what version of Java you are trying to use and also how you have compiled and run the sample. Have you included the blucove.jar file included with leJOS in your classpath?

Do you already have Bluetooth setup and working? Are you able to run the standard leJOS tool nxjbrowse over Bluetooth from your PC to your NXT? If not I would make sure that you can get this working first, it uses the same classes as the samples and will check that your system is working properly.

So what error exactly are you getting and with which sample? The NXT code is now very old, it may be that it will not work with Java 8, you could try compiling against an older version. If nxjbrowse is working over Bluetooth then you should be able to get the sample to work 9as it in effect uses the same code).

Exception in thread "main" java.lang.ClassCastException: javax.microedition.io.Connector$1 cannot be cast to javax.microedition.io.StreamConnection at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:129) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:280) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:239) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:347) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:362) at BTSend.main(BTSend.java:50)

/** * This is a PC sample. It connects to the NXT, and then * sends an integer and waits for a reply, 100 times. * * Compile this program with javac (not nxjc), and run it * with java. * * You need pccomm.jar and bluecove.jar on the CLASSPATH. * On Linux, you will also need bluecove-gpl.jar on the CLASSPATH. * * Run the program by: * * java BTSend * * Your NXT should be running a sample such as BTReceive or * SignalTest. Run the NXT program first until it is * waiting for a connection, and then run the PC program. * * @author Lawrie Griffiths * */public class BTSend { public static void main(String[] args) { NXTConnector conn = new NXTConnector();

/** * Receive data from another NXT, a PC, a phone, * or another bluetooth device. * * Waits for a connection, receives an int and returns * its negative as a reply, 100 times, and then closes * the connection, and waits for a new one. * * @author Lawrie Griffiths * */public class BTReceive {

In the last error you are trying to run code compiled with Java 8 on a Java 7 JRE. You need to compile your code with a Java 7 SDK. There are lots of examples out there on how to do this for various IDEs.

How are you compiling and running the PC side test program? You need to make sure that the leJOS classes.jar is NOT in the classpath when you compile and run your code, if it is you may get this problem. We supply a set of command line shell scripts that may be of use see:http://www.lejos.org/nxt/nxj/tutorial/P ... dRun.htm#6using nxjpcc to compile and nxjpc to run should have things set correctly (assuming you have not done something like at the leJOS classes to your Java classpath environment variables.)

Exception in thread "main" java.lang.NoClassDefFoundError: javax/bluetooth/DiscoveryListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:195) at lejos.pc.comm.NXTCommFactory.newNXTCommInstance(NXTCommFactory.java:98) at lejos.pc.comm.NXTCommFactory.createNXTComm(NXTCommFactory.java:91) at lejos.pc.comm.NXTConnector.search(NXTConnector.java:111) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:235) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:347) at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:362) at BTSend.main(BTSend.java:49)Caused by: java.lang.ClassNotFoundException: javax.bluetooth.DiscoveryListener at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 21 more

You still have not said how you are compiling and running your pc side programs programs. Have you tried just using the leJOS command line tools nxjpcc and nxjpc? This is by far the easiest way to get things running, you will need to reference a number of additional jar files and these should be setup to do just that.

Because you don't have the project in your IDE set up correctly to use the correct SDK and the correct external jar files. Look at what the bat files do and how they configure things and try and work out how to set up the same configuration with your IDE. Before you ask I have no idea how to do this with Intelij!