0

Below is my full code, it compiles properly within the eclipse IDE, but when I try and export it as a runnable JAR file, it says it exported with errors. Then When I try to run the Jar file, none of the labels or text fields show up, nor does my event handler on the button work. I'm not sure what to change since it compiled properly before it was exported.

public class TaskFrame extends JFrame implements ActionListener {

    private JPanel taskPanel, buttonPanel, viewPanel, titlePanel;
    private JButton editButton;
    private String[] labelNames = {"Notes", "Paging", "Event Mgmt - Early", "Event Mgmt - Late", "Airhub 2DA",
            "Airhub 1DA", "GSSD", "GSSI", "GSSRR", "Holdovers", "Radio", "PTI", "Phones 1300", "Publishing"};
    private JLabel[] labelArray = new JLabel[labelNames.length];
    private JLabel titleLabel = new JLabel("Task Dashboard");
    private JTextField[] textArray = new JTextField[labelNames.length];
    private String[] namesArray = new String[labelNames.length];
    private Font titleFont = new Font("Helvetica", Font.BOLD, 24);
    private Color backgroundColor = new Color(255,250,245);



    @Override
    public void actionPerformed(ActionEvent arg0) {

    }

    public static void main(String[] args) {
        TaskFrame frame = new TaskFrame();
        frame.setTitle("Task List");
        frame.setSize(300, 450);
        frame.setResizable(false);
        frame.setVisible(true);

    }

    public TaskFrame() {

        //Create the locked task panel

        taskPanel = new JPanel(new GridLayout(14,2,1,2));
        buttonPanel = new JPanel(new FlowLayout());
        titlePanel = new JPanel(new FlowLayout());
        titleLabel.setFont(titleFont);
        titlePanel.add(titleLabel, SwingConstants.CENTER);
        viewPanel = new JPanel(new FlowLayout());


        //create the button object and assign the event handler

        editButton = new JButton("Edit Tasks");
        editButton.setPreferredSize(new Dimension(100,25));
        editButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                if(!textArray[0].isEditable()) {

                    for(int i = 0; i < labelNames.length; i++) {
                        textArray[i].setEditable(true);
                    }

                    editButton.setText("Save Tasks");

                } else {
                    try {
                        PrintWriter writeNames = new PrintWriter("Techs.txt", "UTF-8");
                        for(int i = 0; i < labelNames.length; i ++) {
                            writeNames.println(textArray[i].getText());
                            textArray[i].setEditable(false);
                            }
                        writeNames.close();
                    } catch (FileNotFoundException e1) {
                        e1.getMessage();
                    } catch (UnsupportedEncodingException e1) {
                        e1.getMessage();
                    }
                }
            }
        });

        buttonPanel.add(editButton);


        //Loop to create all the viewPanel objects, JLabels and JTextFields
        try {
            FileReader fr = new FileReader("Techs.txt");
            BufferedReader br = new BufferedReader(fr);
            for(int i = 0; i < labelNames.length; i++) {
                labelArray[i] = new JLabel(labelNames[i] + ": ", SwingConstants.LEFT);
                textArray[i] = new JTextField(10);
                namesArray[i] = new String();
                namesArray[i] = br.readLine();
                textArray[i].setText(namesArray[i]);
                textArray[i].setEditable(false);
                taskPanel.add(labelArray[i]);
                taskPanel.add(textArray[i]);
            }
        } catch (FileNotFoundException e1) {
            e1.getMessage();
        } catch (IOException e1) {
            e1.getMessage();
        }


        //Assign the defined background color to all panels
        titlePanel.setBackground(backgroundColor);
        taskPanel.setBackground(backgroundColor);
        buttonPanel.setBackground(backgroundColor);
        viewPanel.setBackground(backgroundColor);

        viewPanel.add(titlePanel, BorderLayout.NORTH);
        viewPanel.add(taskPanel, BorderLayout.CENTER);
        viewPanel.add(buttonPanel, BorderLayout.SOUTH);

        add(viewPanel);
        viewPanel.setVisible(true);
    }

}
  • did you use dependencies that are not included in a normal JRE? if so, you have to explicitly tell eclipse that they should be exported as well – Japu_D_Cret Mar 30 '17 at 07:57
  • possible duplicate of http://stackoverflow.com/questions/10024894/why-is-the-eclipse-jar-file-generating-compile-errors-when-the-application-does – Japu_D_Cret Mar 30 '17 at 07:58
  • *"..it compiles properly within the eclipse IDE"* Did you try *running* the code? I got a `NullPointerException` on clicking the button. – Andrew Thompson Mar 30 '17 at 08:13
  • See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) – Andrew Thompson Mar 30 '17 at 08:14
  • I think your "Techs.txt" can't be read when the application is bundled as a jar. Unfortunately you just catch the FileNotFoundException so you are not informed about that. When you click the button you get a NullpointerException as the JTextField isn't there at index 0. It wasn't created as the file couldn't be read. So try to use an absolute path to your Techs.txt for testing purposes. – JanTheGun Mar 30 '17 at 08:18
  • `private Font titleFont = new Font("Helvetica", Font.BOLD, 24);` The Helvetica font will probably not be available on Windows or *nix. Use `Font.SANS_SERIF` for Helvetica on OS X, Arial on Windows, and whatever is the default undecorated text on Linux/Unix systems. – Andrew Thompson Mar 30 '17 at 12:13
  • *"Edit: I'm an actual Idiot, and didn't provide a Techs.txt doc where the code was looking."* Don't put what is effectively the solution, into the question. Either a) delete the question, b) Ask someone like @JanTheGun to upgrade their comment to an answer. or c) answer it yourself. - of those approaches, I'd most prefer to see (b) happen, since it seems that JanTheGun was the first to identify the core problem. – Andrew Thompson Mar 31 '17 at 12:23

0 Answers0