The problem I am having is getting the out of bounds exception to work without calling either of the other two catches.
I don't really get the above, but I have a few corrections to add.
First, don't use the toString method of the exception. Use the getMessage to print the error. String output2 = "Incorrect datatype entered for textfield 2\n" +
"Occured after pressing enter in the 1st textfield\n" +
"Enter appropriate datatype\n" + ex2.getMessage();
And secondly whenever you catch an exception, you print the error and then you continue with the execution of the program. If an exception occurred (user entered non numeric) you shouldn't continue with the rest of the program. So I would suggest to put a return statement at the end of each catch:
catch (Exception ob) {
String output2 = "Index is out of bounds\n" +
"Exception occured after pressing enter in the first textfield\n" +
"Re-enter a selection in the range of " + MIN_INDEX + " - " + MAX_INDEX;
ob.toString();
JOptionPane.showMessageDialog(null, output2);
<strong>return;</strong>
}
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Help please!!!
I am having this exception when I run my prog
[code]Exception in thread "main" java.lang.NullPointerException)[icode]
[code]at PatientReg.displaySQLErrors(PatientReg.java:423)[icode]
here are the codes for each line
[Code] private void displaySQLErrors(SQLException e) {
errorText.append("SQLException: " + e.getMessage() + "\n");
errorText.append("SQLState: " + e.getSQLState() + "\n");
errorText.append("VendorError: " + e.getErrorCode() + "\n");
}
[iCode]
at PatientReg.loadAccounts(PatientReg.java:68)
[Code] private void loadAccounts() {
Vector v = new Vector();
try {
rs = statement.executeQuery("SELECT * FROM PatientTable");
while (rs.next()) {
v.addElement(rs.getString("patienNo"));
}
} catch (SQLException e) {
displaySQLErrors(e);
}
PatientNumberList.setListData(v);
}[iCode]
at PatientReg.buildGUI(PatientReg.java:78)
[Code] loadAccounts();[iCode]
at PatientReg.main(PatientReg.java:443)
[Code] public static void main(String[] args) {
PatientReg patient = new PatientReg();
patient.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
patient.init();
patient.buildGUI();
}
}[iCode]
Please help me I going :icon_mad: with this project. If you need the whole code , I'll be very willing to post it.
JBeginer7891
Junior Poster in Training
59 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Help please!!!
I am having this exception when I run my prog
[code]Exception in thread "main" java.lang.NullPointerException)[icode]
[code]at PatientReg.displaySQLErrors(PatientReg.java:423)[icode]
here are the codes for each line
[Code] private void displaySQLErrors(SQLException e) {
errorText.append("SQLException: " + e.getMessage() + "\n");
errorText.append("SQLState: " + e.getSQLState() + "\n");
errorText.append("VendorError: " + e.getErrorCode() + "\n");
}
[iCode]
at PatientReg.loadAccounts(PatientReg.java:68)
[Code] private void loadAccounts() {
Vector v = new Vector();
try {
rs = statement.executeQuery("SELECT * FROM PatientTable");
while (rs.next()) {
v.addElement(rs.getString("patienNo"));
}
} catch (SQLException e) {
displaySQLErrors(e);
}
PatientNumberList.setListData(v);
}[iCode]
at PatientReg.buildGUI(PatientReg.java:78)
[Code] loadAccounts();[iCode]
at PatientReg.main(PatientReg.java:443)
[Code] public static void main(String[] args) {
PatientReg patient = new PatientReg();
patient.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
patient.init();
patient.buildGUI();
}
}[iCode]
Please help me I going with this project. If you need the whole code , I'll be very willing to post it.
JBeginer7891
Junior Poster in Training
59 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Start a new thread and use code tags.
When you start a code tag: [CODE], finish it with the same by adding the '/' character. You added this code tag:
[CODE]
and then you finish it like this: [/ICODE]
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448