Search code examples
javacompiler-errorsimagej

What's wrong with my ImageJ Plugin Code?


So thanks to some very helpful people I was able to get started on coding this macro.

However I am running into tons of errors (compiling through Fiji).

First here is my code (I have no clue where there error is coming from so I'm posting all of it):

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;

public class Test_Plugin implements PlugIn {



    private void getFile(String dirPath) {
        try {
            Files.find(Paths.get(dirPath), 1, (path, basicFileAttributes) -> (path.toFile().getName().contains("DAPI"))).forEach(dapiPath) -> {
                    Path gfpPath = dapiPath.resolveSibling(dapiPath.getFileName().toString().replace("DAPI", "GFP"));
                    doSomething(dapiPath, gfpPath);
             }  
        }catch(IOException e){
             e.printStackTrace();
        }
    }


    //Dummy method does nothing yet.

    private void doSomething(Path dapiPath, Path gfpPath) {
      System.out.println(dapiPath.toAbsolutePath().toString());
      System.out.println(gfpPath.toAbsolutePath().toString());
    }

}

I'm really lost as to where the errors are coming from. I feel like I'm missing a syntax error somewhere but I cannot find it.

I checked the way that the methods are called and it seems fine to me.

Here are the errors it is throwing up:

Test Errors Test Errors


Solution

  • As you can see in the first lines of the stack trace in your screenshot, your Java code is full of syntax errors (starting from line 14).

    If you really want to develop in Java, the recommended way is to use an IDE like Eclipse or Netbeans. If you open your code in one of these, you'll see a lot of warnings that you can fix even before compiling the code. Please also consider reading some Java tutorials to learn the basics.

    If you don't have any experience in Java programming, I recommend using one of the scripting languages that Fiji understands. For example, you can even paste any Java code and run it as a Groovy script in the script editor without the need for compiling it.