0

I’m having problems with a packaged program I built using the NetBeans IDE and Java Swing. When the project is built from netbeans, it copies all the libraries the program is dependent on, including the sqlite4java API that I use into a folder called lib within the folder dist. Dist also holds the executable .jar file. When the file is opened, the normal jFrame opens and the program runs fine until a SQLiteConnection is called. No errors are returned, but the program always fails to go past that point in the executable .jar file. It works fine in the NetBeans IDE however.

The program has a text area displayed, and a swing worker is used to continuously append the text area with new strings grabbed from a database.

All the variables not included in the code segment are properly instantiated.

Here is the code in question:

int state = evt.getStateChange();

String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());

    //gets the item state i.e. pushed or unpushed
    if (evt.getSource() == Record) {
        Displays.setText("");
        Displays.setEditable(false);
        if (worker != null) {
            worker.cancel(true);
        }
        worker = new SwingWorker() {
            @Override
            protected Integer doInBackground()//Perform the required GUI update here.
            {
                try {
                    //x is created to keep track of the amount of 
                    //previously displayed headers so no headers are displayed more than once
                    int x = 0;

                    //while the button is pushed down
                    while (state == evt.SELECTED) {

                        ArrayList<ArrayList<String>> urlnames = new ArrayList<>();
                        System.out.println(timeStamp);

                        Displays.append("reached");
                        SQLiteConnection db = new SQLiteConnection(new File("my file path"));

                        Displays.append("reached2");
                        db.open(true);

                        //sql statement to find headerurls later than the original starttime
                        SQLiteStatement st = db.prepare("SELECT url FROM urls Where datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime') >= \"" + timeStamp + "\" ORDER BY last_visit_time ASC");
                        urlnames.add(new ArrayList<>());

                        try {
                            while (st.step()) {
                                urlnames.get(0).add(st.columnString(0));
                            }

                            urlnames.add(new ArrayList<>());

                            //gathers each header's respective times
                            st = db.prepare("SELECT datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime') as times FROM urls Where times >= \"" + timeStamp + "\" ORDER BY last_visit_time ASC");
                            while (st.step()) {
                                urlnames.get(1).add(st.columnString(0));
                            }

                        } finally {
                            st.dispose();
                        }

                        //ends connection
                        db.dispose();

                        //prints only the recently added headers
                        for (int i = 0; i < urlnames.get(0).size() - x; i++) {
                            System.out.printf(" %s  %s   %s   %s  \n", "Time visited: ", urlnames.get(1).get(x + i), "       website url:", urlnames.get(0).get(x + i));
                            Displays.append("Time visited: " + urlnames.get(1).get(x + i) + " \t website url:" + urlnames.get(0).get(x + i) + " \n");
                        }

                        System.out.println(x);
                        //change x to account for the new size of the headers and waits 3 seconds before running through again
                        x = urlnames.get(0).size();
                        Thread.sleep(2000);
                        urlnames.clear();
                    }

                } catch (Exception ex) {
                }
                return 0;
            }
        };
        worker.execute();//Schedules this SwingWorker for execution on a worker thread.
    }

The first string "Reached" is always appended to the Text Area, but the second string "Reached2" never makes it. This problem only occurs when I build my program in NetBeans and packge it as a distributable .jar file with the dependent libraries included. The program otherwsie works fine within the NetBeans IDE.

A Zhang
  • 23
  • 4

1 Answers1

0

You catch all exceptions but do not print them. Change

} catch (Exception ex) {
}

to

} catch (Exception ex) {
   ex.printStackTrace();
   Displays.append("exception thrown: " + ex);
}

And you may see an error message that would explain the problem.

Also "my file path" should probably be an absolute path. The current user directory may be different running inside verses outside Netbeans and explain a relative path not working.

WillShackleford
  • 6,918
  • 2
  • 17
  • 33