Login  Register

Re: Version Detection?

Posted by ctrueden on Oct 08, 2007; 8:30pm
URL: http://imagej.273.s1.nabble.com/Version-Detection-tp3698245p3698248.html

Hi Andy,

My experience is that any direct class references you make in a Java
application, sometimes even in branches of code that aren't actually
executed, will result in the class loader trying to load that class.

Instead of:
   imp instanceof ij.plugin.FITS
you could try:
   imp.getClass().getName().equals("ij.plugin.FITS")

There is a difference in behavior regarding subclasses, but in your
case that shouldn't be an issue.

-Curtis

On 10/8/07, Andy Puckett <[hidden email]> wrote:

> Ok, I find this really annoying.  I'm running the following code:
>
>                 String ijvers = IJ.getVersion();
>
>                 if (ijvers.compareTo("1.38f") < 0) {
>                         IJ.log("ImageJ: older");
>                         if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) {
>                                 IJ.error( "Must select a Nova compatible FITS image." );
>                                 return;
>                         }
>                 } else {
>                         IJ.log("ImageJ: newer");
>                         if (imp.getStackSize() < 2 && !(imp instanceof
> ij.plugin.FITS_Reader)) {
>                                 IJ.error( "Must select a Nova compatible FITS image." );
>                                 return;
>                         }
>                 }
>
> Now, even though I'm running ImageJ 1.38x and the code correctly
> responds with "ImageJ: newer" in the log file (so the ELSE clause is
> being used), I still get this error message:
>
>         /Applications/ImageJ/plugins/Nova20071008/Nova_Plugin_.java:54:
>          Class ij.plugin.FITS not found.
>                         if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) {
>
> So, Java will still examine (and reject) the code of the THEN clause,
> even though I've told it to use the ELSE clause for versions of
> ImageJ that don't have the FITS class???  That's idiotic.
>
> Ok, bitching aside... any suggestions?
>
> Thanks,
> Andy
>