Re: [fiji-devel] Problem with class Line in Fiji plugin dvelopment

62 views
Skip to first unread message

Wayne Rasband

unread,
Mar 13, 2013, 2:10:11 PM3/13/13
to Fiji Developers
On Mar 13, 2013, at 6:24 AM, gerald...@gmail.com wrote:

> Hi,
>
> I recently started to use Fiji instead of ImageJ. I am working at the development of some plugins. Now Fiji does not compilate plugins using the ij.gui.Line class.
> The error message is (one example):
> symbol : constructor Line(double,double,double,double)
> location: class Line
> addToRoiManager(new Line(p.getX(), p.getY(), pI.getX(), pI.getY()), name);
>
> The constructor Line(double,double,double,double) does exist, and it worked before. I also tried other constructors, but it seems like the class Line entirely has disappeared from the Fiji API?
>
> Thank you in advance for any help on that.

I am able to reproduce this problem using this test plugin.

import ij.*;
import ij.gui.*;
import ij.plugin.*;
public class My_Plugin implements PlugIn {
public void run(String arg) {
ImagePlus imp = IJ.getImage();
Line line = new Line(10.5, 10.5, 100.5, 100.5);
imp.setRoi(line);
}
}

It works as expected on ImageJ but on a fully updated version of Fiji I get the error message:

/Applications/Fiji.app/plugins/My_Plugin.java:13: cannot find symbol
symbol : method setRoi(Line)
location: class ij.ImagePlus
imp.setRoi(line);

If I change

Line line = new Line(10.5, 10.5, 100.5, 100.5);

to

Roi line = new Line(10.5, 10.5, 100.5, 100.5);

I get this error message:

/Applications/Fiji.app/plugins/My_Plugin.java:12: cannot find symbol
symbol : constructor Line(double,double,double,double)
location: class Line
Roi line = new Line(10.5, 10.5, 100.5, 100.5);

-wayne



Curtis Rueden

unread,
Mar 13, 2013, 2:13:59 PM3/13/13
to Wayne Rasband, Fiji Developers
Hi all,

The following plugin works as expected:

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Line;
import ij.plugin.PlugIn;
public class Draw_Line implements PlugIn {
@Override

public void run(String arg) {
ImagePlus imp = IJ.getImage();
Line line = new Line(0.0, 0.0, imp.getWidth(), imp.getHeight());
imp.setRoi(line);
}
}

But if you change the "ij.gui" import to:
import ij.gui.*;

Then I see similar errors:

Started Draw_Line.java at Wed Mar 13 13:11:45 CDT 2013
Started Draw_Line.java at Wed Mar 13 13:12:19 CDT 2013
/Users/curtis/Desktop/Draw_Line.java:10: cannot find symbol
symbol  : constructor Line(double,double,int,int)
location: class Line
Line line = new Line(0.0, 0.0, imp.getWidth(), imp.getHeight());
           ^
/Users/curtis/Desktop/Draw_Line.java:11: cannot find symbol

symbol  : method setRoi(Line)
location: class ij.ImagePlus
imp.setRoi(line);
  ^
2 errors

Regards,
Curtis





--
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-devel

---
You received this message because you are subscribed to the Google Groups "Fiji-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fiji-devel+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Johannes Schindelin

unread,
Mar 13, 2013, 4:04:07 PM3/13/13
to Curtis Rueden, Wayne Rasband, Fiji Developers
Hi Curtis,
Good catch. This is why I recommend strongly against using .* imports.
Such imports really are asking for trouble.

Ciao,
Johannes

Johannes Schindelin

unread,
Mar 13, 2013, 5:03:48 PM3/13/13
to Wayne Rasband, Curtis Rueden, fi...@fiji.sc
Hi Wayne,

re-Cc:ing the Fiji list because I find it more logical to avoid excluding
the interested parties in the result of our discussions.

On Wed, 13 Mar 2013, Wayne Rasband wrote:

> On Mar 13, 2013, at 4:04 PM, Johannes Schindelin wrote:
>
> > Good catch. This is why I recommend strongly against using .* imports.
> > Such imports really are asking for trouble.
>
> There is still a problem even without the .* imports.
>
> This test plugin:
>
> import ij.IJ;
> import ij.ImagePlus;
> import ij.gui.Roi;
> import ij.plugin.PlugIn;
> public class My_Plugin implements PlugIn {
> public void run(String arg) {
> ImagePlus imp = IJ.getImage();
> Roi line = new Line(10.5, 10.5, 100.5, 100.5);
> imp.setRoi(line);
> }
> }
>
> Generates this error:
>
> Started My_Plugin.java at Wed Mar 13 16:11:14 EDT 2013
> /Applications/Fiji.app/plugins/My_Plugin.java:8: cannot find symbol
> symbol : constructor Line(double,double,double,double)
> location: class Line
> Roi line = new Line(10.5, 10.5, 100.5, 100.5);

You will find that adding "import ij.gui.Line;" before the class
definition will fix it.

Ciao,
Johannes

Curtis Rueden

unread,
Mar 13, 2013, 11:06:32 PM3/13/13
to Johannes Schindelin, Wayne Rasband, Fiji Developers
Hi Dscho,

> This is why I recommend strongly against using .* imports.

I agree about using wildcards with imports, but I still find it mysterious that the line "import ij.gui.*;" causes compile errors in this case. The problematic example I sent compiles fine with the Eclipse compiler, and fine with Apple's Java 1.6.0_43 via Maven from the command line. Any idea why?

Regards,
Curtis

Johannes Schindelin

unread,
Mar 14, 2013, 10:52:39 AM3/14/13
to Curtis Rueden, Wayne Rasband, Fiji Developers
Hi Curtis,

On Wed, 13 Mar 2013, Curtis Rueden wrote:

> > This is why I recommend strongly against using .* imports.
>
> I agree about using wildcards with imports, but I still find it
> mysterious that the line "import ij.gui.*;" causes compile errors in
> this case. The problematic example I sent compiles fine with the Eclipse
> compiler, and fine with Apple's Java 1.6.0_43 via Maven from the command
> line. Any idea why?

Of course. In Wayne's example, "Line" must have been picked up from the
default package since he did not have any import that could match
ij.gui.Line. And indeed:

$ fiji plugins/Scripts/Plugins/Utilities/Find_Jar_For_Class.bsh Line
The class Line is contained in /home/mike/fiji/plugins/Volume_Viewer-2.01.1-SNAPSHOT.jar

Ciao,
Dscho

Curtis Rueden

unread,
Mar 14, 2013, 12:51:15 PM3/14/13
to Johannes Schindelin, Gerald Torgersen, Wayne Rasband, Fiji Developers
Hi Dscho & everyone,

> "Line" must have been picked up from the default package

Wow, interesting that a class in the default package space would silently supersede one imported via wildcards. I would expect either the opposite behavior, or better, a compile-time exception mentioning the name clash similar to when you have two conflicting wildcard imports. E.g.:

NameClashImport.java:7: reference to List is ambiguous, both class java.util.List in java.util and class java.awt.List in java.awt match
List list;
^
1 error

Too bad that the default package is given so much precedence...

Anyway, Gerald: the lesson is to add "import ij.gui.Line;" explicitly to the top of your plugin. Let us know if the problem still persists.

Regards,
Curtis
Reply all
Reply to author
Forward
0 new messages