Click here to Skip to main content
15,882,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having a terrible time getting this code to work. I either get an exception at main or a jd2xx not in java.class.path

I am relatively new to java and am using NetBeans as my IDE. I would really appreciate it if someone could take a peek at the code and tell me how to get in running in NetBeans or even via command line.

When I run the test application I get this:
>
MSIL
java -Djava.library.path=".." -cp "../jd2xx.jar;." TestListener
Exception in thread "main" java.lang.NoClassDefFoundError: TestListener
Caused by: java.lang.ClassNotFoundException: TestListener
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)



CODE HERE[] is found at the bottom here

I have included two versions of the jd2xx source code from two project that have it working. All I should need is the jd2xx.jar and jd2xx.dll and it should work.

In my project (I just copy-pasted the TestListener.java into a NetBeans project) have the jar included in my libraries and the IDE can resolve functions inside it but when I try to run it it gives jd2xx.jar not in java.class.path. My jar manifest says:
<pre lang="vb">Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Main-Class: Test.Run
Class-Path: lib/jd2xx.jar
X-COMMENT: Main-Class will be added automatically by build


And under ./dist/ theirs my jar and jd2xx.jar in in ./dist/lib

Help is appreciated, I bet its just an environment variable or something that's messed up...

package test;

import java.io.IOException;

import jd2xx.JD2XX;
import jd2xx.JD2XXEvent;
import jd2xx.JD2XXEventListener;

public class TestListener implements Runnable, JD2XXEventListener {

	public TestListener() {
	}

	public static void main(String[] args) throws Exception {
		TestListener tl = new TestListener();

		JD2XX jd = new JD2XX();
		jd.open(0);

		jd.addEventListener(tl);
		jd.notifyOnEvent(JD2XX.EVENT_RXCHAR | JD2XX.EVENT_MODEM_STATUS, true);

		Thread tester = new Thread(tl);
		tester.start();

		try { Thread.sleep(15*1000); }
		catch (InterruptedException e) {
			System.out.println("InterruptedException");
		}

		jd.notifyOnEvent(~0, false);
	}

	public void jd2xxEvent(JD2XXEvent ev) {
		JD2XX jd = (JD2XX)ev.getSource();
		int et = ev.getEventType();

		try {
			if ((et & JD2XX.EVENT_RXCHAR) != 0) {
				int r = jd.getQueueStatus();
				System.out.println("RX event: " + new String(jd.read(r)));
			}
			if ((et & JD2XX.EVENT_MODEM_STATUS) != 0) {
				System.out.println("Modem status event");
			}
		}
		catch (IOException e) {
			System.out.println("IOException");
		}
	}

	public void run() {
		try {
			while (true) {
				Thread.sleep(1*1000);
				System.out.println("Too much work and no play makes Duke a dull boy");
			}
		}
		catch (InterruptedException e) {
			System.out.println("InterruptedException");
		}
	}

}
Posted
Updated 4-Jul-11 20:29pm
v3
Comments
TorstenH. 5-Jul-11 2:31am    
added the code of the TestListener here

Check if the jd2xx.jar (what ever that is!?) is included in the build process. If it's a native Java project you should check the project properties.
 
Share this answer
 
Comments
Trevor Johansen 5-Jul-11 7:21am    
I have the jd2xx.jar included in my compile and run paths in NetBeans and when I run my jar with "-Djava.class.path="path to jd2xx.jar" and -cp "path to jd2xx.jar" it says that it can not find jd2xx in the java.class.path

Here is my NetBeans project if that helps:
http://www.4shared.com/file/EGLVyDnm/jd2xx_Test.html
Trevor Johansen 5-Jul-11 7:23am    
jd2xx.jar Is a guys implementation of FTDI's serial/FIFO USB communications chips bit-bang driver.

I am using Java instead of c/c++ as my app needs to run on Windows and Linux.
OK, so strangely enough I solved my problems through another issue I was having. One of my well know Java apps that ran fine before stopped responding and It was due to the fact that the /usr/bin/java shortcut had been updated to a different version of the VM.

sudo update-alternatives --config java


That was the command to set things back to their original settings (I chose the official Sun VM) and now my TestListiner package works just as it should.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900