Skip to content

Commit

Permalink
Merge pull request #26 from dinesh-it/dinesh
Browse files Browse the repository at this point in the history
Minor NULL pointer exception fix
  • Loading branch information
VenkatesanNarayanan committed Sep 14, 2015
2 parents fdffc12 + 5dc458d commit c46c876
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/UserInterface/pnl_wheels_add.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@


public class pnl_wheels_add extends JPanel implements TableModelListener {

private static final long serialVersionUID = 1L;

private JTextField txt_mobile_no, txt_customer_name, txt_vehicle_make, txt_date, txt_time;
private JTextArea txt_comment;
private JTable tbl_particulars;
Expand All @@ -65,9 +65,9 @@ public pnl_wheels_add() {
pnl_customer_details.setBounds(17, 40, 941, 128);
add(pnl_customer_details);
pnl_customer_details.setLayout(null);



int now_epoch = Time.now();

JLabel lbl_mobile_no = new JLabel("Mobile No");
Expand Down Expand Up @@ -372,7 +372,7 @@ else if(!customer.getName().equalsIgnoreCase(c_name) || !customer.getMobile().eq
customer_id = dbh.add_customer(c_name, c_mobile, " ", " ", 1, date_epoch);
vehicle_id = dbh.add_customer_vehicle(customer_id, v_num, v_make, 1, date_epoch);
}

int bill_id = dbh.add_service_bill(vehicle_id, comment, total_amount, 1, date_epoch);
ServiceBill service_bill = new ServiceBill(vehicle_id, comment, total_amount, 1, date_epoch);
service_bill.setId(bill_id);
Expand Down Expand Up @@ -493,7 +493,7 @@ private boolean validate_details() {
txt_date.requestFocus();
return false;
}

if(!time.matches(Formatter.TIME_PATTERN)){
alert("Please enter a valid time in hh:mm am/pm format");
txt_time.requestFocus();
Expand Down Expand Up @@ -526,7 +526,7 @@ public void tableChanged(TableModelEvent e) {
int column = e.getColumn();
Pattern pattern = Pattern.compile("(^\\d+\\.?\\d*$)");


String current_cell_str = tbl_particulars.getValueAt(row, column).toString();
if((! current_cell_str.trim().isEmpty()) && (!pattern.matcher(current_cell_str).find())){
if(column == 3 )
Expand All @@ -542,7 +542,7 @@ else if(column == 2)
// parsing null value will throw NumberFormatException
// To avoid that exception amount stored in string
String str_amount = tbl_particulars.getValueAt(row, 3).toString();


if(! str_amount.trim().isEmpty()){

Expand All @@ -552,13 +552,13 @@ else if(column == 2)
if(is_multiple[row].toString() == "false") {
total = amount;
} else {

int quan = 1;
if( tbl_particulars.getValueAt(row, 2) != null)
quan = Integer.parseInt(tbl_particulars.getValueAt(row, 2).toString());
else
tbl_particulars.setValueAt(new Integer(1), row, 2);

total = amount * quan;
}

Expand Down Expand Up @@ -592,7 +592,12 @@ public String[][] getTableData (JTable table) {
String[][] tableData = new String[nRow][nCol];
for (int i = 0 ; i < nRow ; i++)
for (int j = 0 ; j < nCol ; j++)
tableData[i][j] = dtm.getValueAt(i,j).toString();
if(dtm.getValueAt(i,j) != null){
tableData[i][j] = dtm.getValueAt(i,j).toString();
}
else{
tableData[i][j] = null;
}
return tableData;
}

Expand Down

0 comments on commit c46c876

Please sign in to comment.