Login  Register

Re: java null pointer exception / no window found

Posted by Wayne Rasband-2 on Aug 31, 2018; 3:46pm
URL: http://imagej.273.s1.nabble.com/java-null-pointer-exception-no-window-found-tp5021141p5021146.html

> On Aug 31, 2018, at 5:31 AM, Agnieszka <[hidden email]> wrote:
>
> Hello,
>
> I am new to writing macros for ImageJ/Fiji and I tried to create a macro
> that would perform particle analysis. At first I duplicate the oryginal
> image, apply a filter and then substract images. I apply a certain treshold
> and perform the particle analysis. The macro allows also to choose the
> channel on which I would like to perform this analysis. To import images I
> use Bio-Formats.
>
> First, I created the macro on my mac (High Sierra 10.13.6, ImageJ version
> 2.0.0-rc-68/1.52e) and it works without any problems generating the results
> that I want. My collegues tried running it on their computers (Windows) and
> it results in java.lang.Nullpointer exception (attached file) as well as
> "No window with the title "Image 1_Maximum intensity projection.czi - C=1"
> found.”

The latest ImageJ daily build (1.52f42) fixes a bug could cause the ImagePlus.getFileInfo() method (used by the saveAs("Tiff”,path) macro function) to throw a null pointer exception. The ‘input’ and ‘output’ directory paths in the macro also need to be updated to work on Windows.

-wayne


> They tried updating Fiji but it didn't change the problem. I have seen posts
> regarding this Nullpointer exception but I could find problem similar to
> mine or the they say this problem was solved with an update.
>
> At this point I don't have a clue where this problem is coming from so I
> would appreciate any help.
>
> Thanks,
> Agnieszka
>
> My macro:
>
> input = "/Users/agnieszka/Documents/test_images/";
> output = "/Users/agnieszka/Documents/Results-test/";
> channel = "1"; // channel 0 or 1
>
> function Action(input, output, filename) {
>
> run("Bio-Formats Importer", "open=[" + input + filename + "]" + "
> autoscale color_mode=Default rois_import=[ROI manager] split_channels
> view=Hyperstack stack_order=XYCZT");
>
> number = "-1"; // used to create duplicated file name e.g. filename-1
> fileWithoutExtension = replace(filename, "\.czi", "");
> fileWithoutExtensionC = fileWithoutExtension + "_C" + channel; // used for
> saving of output files
> filenameC = filename +  " - C=" + channel; // used by further commands
> filename_duplicated = filenameC + number;
>
> selectWindow(filenameC);
> run("Duplicate...", " ");
> run("Median...", "radius=5");
> imageCalculator("Subtract create", filenameC, filename_duplicated);
> selectWindow(filenameC);
> close();
> selectWindow(filename_duplicated);
> close();
> setThreshold(30, 255);
> saveAs("Tiff", output + fileWithoutExtensionC + ".tif");
> // adds 0 to the results table in case there are no particles found:
> run("Clear Results");
> setResult("Area", nResults, "0");
> run("Analyze Particles...", "  show=[Bare Outlines] display summarize");
> IJ.deleteRows(0, 0);
> saveAs("Tiff", output + "Drawing of Result of " + fileWithoutExtensionC +
> ".tif");
> Table.rename("Results", "Results" + fileWithoutExtensionC);
> saveAs("Results", output + "Results_" + fileWithoutExtensionC + ".csv");
> close();
> close();
> run("Close");  
> }
>
> setBatchMode(true);
> list = getFileList(input);
> for (i = 0; i < list.length; i++)
>        Action(input, output, list[i]);
> selectWindow("Summary");
> saveAs("Text", output + "SummaryC" + channel + ".csv");      
> setBatchMode(false);
>
> Java_exception.txt
> <http://imagej.1557.x6.nabble.com/file/t382093/Java_exception.txt>  
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html