dennisegen / MOST

MOST - Metabolic Optimization and Simulation Tool
3 stars 4 forks source link

GurobiPathInterface error #81

Closed mentatpsi closed 10 years ago

mentatpsi commented 11 years ago

I'm not sure if anyone else runs into this problem, but there have been several times that I've been modifying code and upon attempting to run the gurobi path interface it comes up with this error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at edu.rutgers.MOST.presentation.GraphicalInterface$73.actionPerformed(GraphicalInterface.java:1725)

Where 1725 is the following: getGurobiPathInterface().setVisible(true);

If I had to make an assumption as to why it is, I've been noticing that it happens when the path interface didn't load upon start up. I guess because it hasn't been initialized. I'm going to try to see if i can fix this.

mentatpsi commented 11 years ago

Yes... I seemed to have found it... the problem is here:

if (lastGurobi_path == null) {
            openGurobiPathFilechooser = true;
            loadGurobiPathInterface();
        }

The issue is if a path is detected... it won't initialize the gurobi path interface and thereby create that error. It needs to be initialized regardless so as not to run into that error. Or at the very least, have a try & catch or if statement that will initialize the gui if it's found not to be. I can go ahead and fix this though.

mentatpsi commented 11 years ago

Ok... here's my fix... I tried to make it a little more compartmentalized:

New method:

public static void createGurobiPathInterface() {
        GurobiPathInterface gpi = new GurobiPathInterface();
        setGurobiPathInterface(gpi);

        gpi.setIconImages(icons);                   
        gpi.setSize(600, 150);
        gpi.setResizable(false);
        gpi.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        gpi.setLocationRelativeTo(null);        
        gpi.setAlwaysOnTop(true);   
        gpi.setModal(true);
        gpi.textField.setText(findGurobiPath());
        if (gurobiPathFound) {
            gpi.topLabel.setText(GraphicalInterfaceConstants.GUROBI_PATH_FOUND_LABEL);
            setGurobiPath(findGurobiPath());
        } else {
            gpi.topLabel.setText(GraphicalInterfaceConstants.GUROBI_PATH_NOT_FOUND_LABEL);
        }
        gpi.fileButton.addActionListener(fileButtonActionListener);
        gpi.okButton.addActionListener(gpiOKActionListener);
        gpi.cancelButton.addActionListener(gpiCancelActionListener);
        gpi.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                gpiCloseAction();               
            }
        }); 
    }

Modifications:

String lastGurobi_path = curSettings.get("LastGurobi");

        createGurobiPathInterface();

        if (lastGurobi_path == null) {
            openGurobiPathFilechooser = true;
            loadGurobiPathInterface();
        }
public static void loadGurobiPathInterface() {
        createGurobiPathInterface();

        getGurobiPathInterface().setVisible(true);

        gurobiPathErrorShown = false;
        openGurobiPathFilechooser = true;
        gurobiFileChooserShown = false; 
    }
mentatpsi commented 11 years ago

Essentially... we just have to merge that code into the working one. I'm working on my own repo and I haven't really merged anything yet.

jimkell commented 10 years ago

This is no longer a bug.