Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with using an API

Status
Not open for further replies.

da644

Programmer
May 21, 2001
159
GB
Hi Everyone.

I'm new to Java, and I need to write a small simple app using an API. The API is imageJ, a collection of image tools. My code is as follows:-

// imageinfo.java

import ij.*;
import ij.io.*;

public class imageinfo
{
public static void main(String [] args)
{
Opener objOpener = new Opener ();
ImagePlus imageObject = objOpener.openImage(args [0]);
System.out.println ("Image Type: " + imageObject.getType());
System.out.println ("Image Dimensions: " + imageObject.getWidth() + 'x' + imageObject.getHeight());
}
}

I'm compiling it in the following way:-

/usr/java/j2sdk1.4.0_03/bin/javac -classpath /opt/imageJ imageinfo.java

And I get no errors... I then run it in the following follow:-

/usr/java/j2sdk1.4.0_03/bin/java -cp /opt/imageJ imageresizer testimage.jpg

And get the following error message:-

Exception in thread "main" java.lang.NoClassDefFoundError: imageresizer

Any ideas?

Best Regards

Andrew.
 
Sorry mistake in the above .... it should read...

/usr/java/j2sdk1.4.0_03/bin/java -cp /opt/imageJ imageinfo testimage.jpg

And the error message should read...

Exception in thread "main" java.lang.NoClassDefFoundError: imageinfo

Best Regards

Andrew.
 
Since imageinfo contains the main method, that should be the class to run. Try this:

/usr/java/j2sdk1.4.0_03/bin/java -cp /opt/imageJ imageinfo testimage.jpg
 
Try this -
/usr/java/j2sdk1.4.0_03/bin/java -cp /opt/imageJ:. imageinfo testimage.jpg


note the extra :. on the end of the -cp

Basically what I think is happening is because you are explicitly giving the java executable a classpath thru the -cp flag, it will look in only that path and no where else, so you need to tell it to look in the directory you are currently residing in (which obviously is what the . does).

The : is the separator like ; is in Windows.


your other option would be to explicitly list the directory location of imageinfo on your -cp if you dont want to be in the same directory everytime you run it. Serves the same result I believe.

Let us know how you get on with it. ----------------------------------------
There are no onions, only magic
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top