Login  Register

ImageJ/FIJI crash on IJ.run(...)

Posted by AJBell on Feb 18, 2014; 2:58pm
URL: http://imagej.273.s1.nabble.com/ImageJ-FIJI-crash-on-IJ-run-tp5006559.html

Dear list,

I have written a set of PlugIns for our image analysis which make use of Threading using the RunnableJob method. The scripts work as intended when launched from the ImageJ or Fiji plugings menu and from the plugins editor. When I try to run the plugin from a button in a Frame, the program hangs.

By excising bits of code, I've narrowed the problem down to several commands, including:

IJ.run("Set Measurements...")
imp.close();

These are commands I have used before with no problems and I cannot see why the program only hangs when started from a button, but not from the main menu.

The following code reproduces the arrangement of the code I have, and gives the same fault. When the IJ.run("set Measurements...") is commented out (line 53, ThreadTest Class), the program runs fine; when it is included, the program crashes. Any suggestions as to what is happening or why would be greatfully received.

Andrew Bell
Research Associate
University of Leicester

//Frame class:
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.frame.*;
import java.awt.event.*;

public class ButtonFrame extends PlugInFrame implements ActionListener {

        public ButtonFrame() {
                super("ButtonFrame");
                Button ta = new Button("Start");
                ta.addActionListener(this);
                add(ta);pack();show();
        }
        public void actionPerformed(ActionEvent e){
                IJ.log("Button Clicked");
                ThreadTest tt = new ThreadTest();
                tt.run("");
        }
}

//Thread class:
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class ThreadTest implements PlugIn {

        public RunnableJob runnableJob = new RunnableJob();
        public String[] str_list = {"Apples","Stairs"};

        public void run(String arg){
               
                for(int i=0; i<str_list.length;i++){
                        try{
                                Thread t = new Thread(runnableJob, str_list[i]);
                                t.start();
                                t.join();
                        }catch (InterruptedException ex) {
                                IJ.showMessage("Error",""+ex);
                        }

                }
                IJ.log("Complete");
        }// end of ThreadTest run

        public class RunnableJob implements Runnable {

                public String name;

                public void run() {
                        Thread thread = Thread.currentThread();
                        name = thread.getName();
                       
                        try {
                                TestFunction tf = new TestFunction();
                                tf.run(name);
                       
                        } catch (Exception e) {
                                IJ.showMessage("Error",""+e);
                        }
                }

        } //end of RunnableJob

        public class TestFunction {

                public void run(String arg){
                        try{
                                int x = (int)(Math.random() * 1000);
                                Thread.sleep(x);
                                IJ.log(arg+" "+x+" ms delay");
                                //IJ.run("Set Measurements...", "area perimeter fit feret's integrated display redirect=None decimal=3");
                        } catch(Exception e){
                                IJ.log(""+e);
                        }
                }
        }// end of TestFunction
} //class end