Home arrow static arrow Java Programming [Archive] - try-catch
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - try-catch
This topic has 26 replies on 2 pages.    1 | 2 | Next »

Posts:54
Registered: 04-06-18
try-catch  
Jul 29, 2004 12:53 PM



 
Every time I "try" to implement the try-catch code in the method below, all of my other methods foul up because of either { or }. The code compiles fine without the try-catch, but when I add it in, it fouls things up? What am I doing wrong?

private void addNewJobHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {
setPastFlag(false);
setNewFlag(true);
setDeleteFlag(false);

setActionFlag(false);

jobHistoryLabel.setText("Add New Job History");
jobHistoryLabel.setForeground(new java.awt.Color(0, 0, 255));

studentComboBox.setEnabled(false);
studentComboBox.removeAllItems();

//clear the form
binder.clearForm();

setActionFlag(true);

try{
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {

Database database = employerBinder.getDatabase();

Vector theValues = new Vector();
Vector values = new Vector();

theValues = database.executeQueryFromLibrary( 92 );
for(int i=0 ; i<theValues.size(); i++) {
values.add(new ListItem(((Vector)theValues.elementAt(i)).elementAt(1).toString(),
((Vector)theValues.elementAt(i)).elementAt(0).toString()));
}

for( int i = 0; i < values.size(); i++ )
studentComboBox.addItem( values.elementAt(i) );

}
});
}
catch(Exception e){
System.out.println("EXCEPTION ERROR: " + e);
}

studentComboBox.setEnabled(true);

revalidate();
repaint();
}
 

Posts:13,769
Registered: 00-11-29
Re: try-catch  
Jul 29, 2004 12:59 PM (reply 1 of 26)



 
repost using [code][/code] tags
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:04 PM (reply 2 of 26)



 
Every time I "try" to implement the try-catch code in the method below, all of my other methods foul up because of either { or }. The code compiles fine without the try-catch, but when I add it in, it fouls things up? What am I doing wrong?

private void addNewJobHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {setPastFlag(false);setNewFlag(true);setDeleteFlag(false); setActionFlag(false); jobHistoryLabel.setText("Add New Job History");jobHistoryLabel.setForeground(new java.awt.Color(0, 0, 255)); studentComboBox.setEnabled(false);studentComboBox.removeAllItems(); //clear the formbinder.clearForm(); setActionFlag(true); try{javax.swing.SwingUtilities.invokeAndWait(new Runnable() {public void run() { Database database = employerBinder.getDatabase(); Vector theValues = new Vector();Vector values = new Vector(); theValues = database.executeQueryFromLibrary( 92 );for(int i=0 ; i<theValues.size(); i++) {values.add(new ListItem(((Vector)theValues.elementAt(i)).elementAt(1).toString(),((Vector)theValues.elementAt(i)).elementAt(0).toString()));} for( int i = 0; i < values.size(); i++ ) studentComboBox.addItem( values.elementAt(i) ); }});}catch(Exception e){System.out.println("EXCEPTION ERROR: " + e);} studentComboBox.setEnabled(true); revalidate();repaint();} 
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:04 PM (reply 3 of 26)



 
I counted all of the { and } and they are equal.
 

Posts:2,206
Registered: 8/15/02
Re: try-catch  
Jul 29, 2004 1:07 PM (reply 4 of 26)



 
Telling us what the error is would also help
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:08 PM (reply 5 of 26)



 
com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [625:1] illegal start of expression    private void deleteSelectedJobHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSelectedJobHistoryButtonActionPerformed    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [766:1] illegal start of expression    private javax.swing.JButton addNewJobHistoryButton;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [767:1] illegal start of expression    private com.asisoftware.util.widgets.address.addressJPanel addressJPanel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [768:1] illegal start of expression    private javax.swing.JLabel assignmentLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [769:1] illegal start of expression    private javax.swing.JTextField assignmentText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [770:1] illegal start of expression    private javax.swing.JButton deleteSelectedJobHistoryButton;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [771:1] illegal start of expression    private javax.swing.JLabel employerLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [772:1] illegal start of expression    private javax.swing.JTextField employerText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [773:1] illegal start of expression    private javax.swing.JLabel endingDateLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [774:1] illegal start of expression    private javax.swing.JTextField endingDateText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [775:1] illegal start of expression    private javax.swing.JLabel endingSalaryLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [776:1] illegal start of expression    private javax.swing.JTextField endingSalaryText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [777:1] illegal start of expression    private javax.swing.JLabel home;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [778:1] illegal start of expression    private com.asisoftware.util.widgets.phone.PhoneNumberJPanel homePhoneJPanel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [779:1] illegal start of expression    private javax.swing.JLabel homePhoneLabel1;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [780:1] illegal start of expression    private javax.swing.JLabel jobExperienceDescriptionLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [781:1] illegal start of expression    private javax.swing.JTextField jobExperienceDescriptionText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [782:1] illegal start of expression    private javax.swing.JLabel jobHistoryLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [783:1] illegal start of expression    private javax.swing.JComboBox jobTitleComboBox;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [784:1] illegal start of expression    private javax.swing.JLabel jobTitleLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [785:1] illegal start of expression    private javax.swing.JLabel money1;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [786:1] illegal start of expression    private javax.swing.JLabel moneyLabel2;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [787:1] illegal start of expression    private javax.swing.JLabel startingDateLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [788:1] illegal start of expression    private javax.swing.JTextField startingDateText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [789:1] illegal start of expression    private javax.swing.JLabel startingSalaryLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [790:1] illegal start of expression    private javax.swing.JTextField startingSalaryText;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [791:1] illegal start of expression    private javax.swing.JComboBox studentComboBox;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [792:1] illegal start of expression    private javax.swing.JLabel studentLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [793:1] illegal start of expression    private javax.swing.JButton viewPastJobHistoryButton;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [794:1] illegal start of expression    private javax.swing.JComboBox workPeriodComboBox;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [795:1] illegal start of expression    private javax.swing.JLabel workPeriodLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [796:1] illegal start of expression    private com.asisoftware.util.widgets.phone.PhoneNumberJPanel workPhoneJPanel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [797:1] illegal start of expression    private javax.swing.JLabel workPhoneLabel;    ^com/asisoftware/placewiz/employer/EmployerJobHistoryJPanel.java [801:1] '}' expected^34 errorsErrors compiling EmployerJobHistoryJPanel [LMod]. 
 

Posts:2,206
Registered: 8/15/02
Re: try-catch  
Jul 29, 2004 1:09 PM (reply 6 of 26)



 
And for the benefit of others...
private void addNewJobHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {    setPastFlag(false);    setNewFlag(true);    setDeleteFlag(false);     setActionFlag(false);     jobHistoryLabel.setText("Add New Job History");    jobHistoryLabel.setForeground(new java.awt.Color(0, 0, 255));     studentComboBox.setEnabled(false);    studentComboBox.removeAllItems();     //clear the form    binder.clearForm();     setActionFlag(true);     try{	javax.swing.SwingUtilities.invokeAndWait(new Runnable() {		public void run() { 		    Database database = employerBinder.getDatabase(); 		    Vector theValues = new Vector();		    Vector values = new Vector(); 		    theValues = database.executeQueryFromLibrary( 92 );		    for(int i=0 ; i<theValues.size(); i++) {			values.add(new ListItem(((Vector)theValues.elementAt(i)).elementAt(1).toString(),						((Vector)theValues.elementAt(i)).elementAt(0).toString()));		    } 		    for( int i = 0; i < values.size(); i++ )			studentComboBox.addItem( values.elementAt(i) ); 		}	    });    }    catch(Exception e){	System.out.println("EXCEPTION ERROR: " + e);    }     studentComboBox.setEnabled(true);     revalidate();    repaint();}
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:10 PM (reply 7 of 26)



 
Thanks Edna. How did you do that?
 

Posts:7,258
Registered: 1/31/02
Re: try-catch  
Jul 29, 2004 1:10 PM (reply 8 of 26)



 
my guess is the trouble lies in this mess:
values.add(new ListItem(((Vector)theValues.elementAt(i)).elementAt(1).toString(),((Vector)theValues.elementAt(i)).elementAt(0).toString()));} for( int i = 0; i < values.size(); i++ ) studentComboBox.addItem( values.elementAt(i) ); }});
That last bit looks no good to me...

(no offense to the OP - I've written my share of messes in my time - though not quite like that :-) - I've not seen that many nested parens since my LISP days!)
 

Posts:2,206
Registered: 8/15/02
Re: try-catch  
Jul 29, 2004 1:12 PM (reply 9 of 26)



 
Thanks Edna. How did you do that?

I copied it into xemacs, told is was java mode, and asked it to autoindent, then copied it back into the forum
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:13 PM (reply 10 of 26)



 
No, everything works when I use this code without the try-catch:

private void addNewJobHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {        setPastFlag(false);        setNewFlag(true);        setDeleteFlag(false);                setActionFlag(false);                jobHistoryLabel.setText("Add New Job History");        jobHistoryLabel.setForeground(new java.awt.Color(0, 0, 255));                studentComboBox.setEnabled(false);        studentComboBox.removeAllItems();                //clear the form        binder.clearForm();                setActionFlag(true);                         Database database = employerBinder.getDatabase();                        Vector theValues = new Vector();            Vector values = new Vector();                        theValues = database.executeQueryFromLibrary( 92 );            for(int i=0 ; i<theValues.size(); i++) {                values.add(new ListItem(((Vector)theValues.elementAt(i)).elementAt(1).toString(),                                        ((Vector)theValues.elementAt(i)).elementAt(0).toString()));            }                    for( int i = 0; i < values.size(); i++ )                      studentComboBox.addItem( values.elementAt(i) );                                studentComboBox.setEnabled(true);                revalidate();        repaint();    }
 

Posts:3,534
Registered: 9/30/99
Re: try-catch  
Jul 29, 2004 1:14 PM (reply 11 of 26)



 
Just before your catch you have a spare ");" stuff between quotes--closing paren and semicolon. The semicolon isn't a big deal, but an extra closing paren will cause great problems.

Try this:

get your code running without the try catch, then on seperate lines put the try catch in like this:
    try{    my code;    my code;    my code;  }catch(Exception e){       System.out.println("EXCEPTION ERROR: " + e);   }


And don't touch your original code. You will see the problem is not the try/catch/finally blocks.
 

Posts:54
Registered: 04-06-18
Re: try-catch  
Jul 29, 2004 1:15 PM (reply 12 of 26)



 
I think it has something to do with the error:
//GEN-FIRST:event_deleteSelectedJobHistoryButtonActionPerformed 
 

Posts:2,206
Registered: 8/15/02
Re: try-catch  
Jul 29, 2004 1:18 PM (reply 13 of 26)



 
get your code running without the try catch, then on
seperate lines put the try catch in like this:

Trouble is he needs the try catch block to get the invokeAndWait to compile.
 

Posts:3,534
Registered: 9/30/99
Re: try-catch  
Jul 29, 2004 1:18 PM (reply 14 of 26)



 
I hate it when we all post at the same time!!!!!!!!!!!!!!
 
This topic has 26 replies on 2 pages.    1 | 2 | Next »