My assignment is about creating a payroll program.Compiler can compile the program and able to run it,however whenever i enter an email address it produce an error.I've been trying to look for the mistakes but couldnt find it.
Here is the error in command prompt:
Exception in thread "main" java.lang.NullPointerException at Employee.validateEmail(employee.java:132) at Employee.empdetails(employee.java:110) at Employee.main(employee.java:40)
source code
import javax.swing.*; class Employee{ static String details; static String name[]= new String [2]; static int dobday[]= new int[2]; static int dobmth[]= new int[2]; static int dobyear[]= new int[2]; static String ic[]= new String[2]; static int adday[]= new int[2]; static int admth[]= new int[2]; static int adyear[]= new int[2]; static double bsalary[]= new double[2]; static String email[]= new String [2]; static String position[]= new String [2]; static String mstatus[]= new String [2]; static String z[] = new String[2]; static String z1[] = new String[2]; static int dd2; static int mm2; static int yyyy2; static int years[]=new int[2]; static double nyallowance[]=new double[2]; static double mrallowance[]=new double[2]; static double costol; static double netsalary[]=new double[2]; static double epf[]=new double[2]; static String marrystatus; static String emp[]=new String[2]; public static void main(String payroll[]){ empdetails (); empid(); wduration(); netsalary(); result(); } static void empdetails(){ String details; int a,b,c,x,j; for(int k=0;k<2;k++){ name[k]=JOptionPane.showInputDialog("Please Enter Your Full Name"); details=JOptionPane.showInputDialog("Enter your date of birth:DAY"); dobday[k]=Integer.parseInt(details); if(dobday[k]>31 && dobday[k]<1){ JOptionPane.showConfirmDialog(null,"Wrong Date, Please enter correct date"); } details=JOptionPane.showInputDialog("Enter your date of birth:MONTH"); dobmth[k]=Integer.parseInt(details); if(dobmth[k]>12 && dobmth[k]<1){ JOptionPane.showConfirmDialog(null,"Wrong Month, Please enter correct Month"); } details=JOptionPane.showInputDialog("Enter your date of birth:YEAR"); dobyear[k]=Integer.parseInt(details); ic[k]=JOptionPane.showInputDialog("Enter your Identification Number"); details=JOptionPane.showInputDialog("Enter your appointed date:DAY"); adday[k]=Integer.parseInt(details); if(adday[k]>31 && adday[k]<1){ JOptionPane.showConfirmDialog(null,"Wrong Date, Please enter correct date"); } details=JOptionPane.showInputDialog("Enter your appointed date:MONTH/(in number not word/)"); admth[k]=Integer.parseInt(details); if(admth[k]>12 && admth[k]<1){ JOptionPane.showConfirmDialog(null,"Wrong Month, Please enter correct Month"); } details=JOptionPane.showInputDialog("Enter your appointed date:YEAR"); adyear[k]=Integer.parseInt(details); details=JOptionPane.showInputDialog("Enter your basic salary"); bsalary[k]=Double.parseDouble(details); details=JOptionPane.showInputDialog("Enter your email address"); validateEmail(); email[k]=details; position[k]=JOptionPane.showInputDialog("Enter your Position Title"); mstatus[k]=JOptionPane.showInputDialog("Enter your marital status:Married or Not Marry"); z[k]=dobday[k]+"//"+dobmth[k]+"//"+dobyear[k]; z1[k]=adday[k]+"//"+admth[k]+"//"+adyear[k]; dd2=adday[k]; mm2=admth[k]; yyyy2=adyear[k]; marrystatus=mstatus[k]; } } static void validateEmail(){ int h=details.indexOf('@'); int i=details.lastIndexOf('.'); int j=details.length(); if(h>0){ if(i!=-1 && i!=(j-1)){ if(h<i && 1<(i-h)){ JOptionPane.showMessageDialog(null,"Valid email"); } else{ JOptionPane.showMessageDialog(null,"Invalid email"); } } else{ JOptionPane.showMessageDialog(null,"Invalid email"); } } else{ JOptionPane.showMessageDialog(null,"Invalid email"); } } static void empid(){ String id,num; int x=0; for(int i=0; i<2; i++){ if (i<20){ id="0"; } else{ id=""; } if(i>1){ num=""; } else{ num="0"; } if(i>0){ x=x+5; } else{ x=0; } emp[i]=id+num+x; System.out.println("EMP"+ emp[i]); } } static void wduration(){ int dd1,mm1,yyyy1,years; dd1 = 11; mm1 = 11; yyyy1 = 2011; if(yyyy1==yyyy2){ if(yyyy1>yyyy2){ years=0; } } if (mm1>mm2){ years=yyyy1-yyyy2; } else{ if (mm1<mm2){ years=yyyy1-yyyy2-1; } else{ if (mm1==mm2){ if (dd1>dd2){ years=yyyy1-yyyy2; } if (dd1<dd2){ years=yyyy1-yyyy2-1; } if (dd1==dd2){ years=yyyy1-yyyy2; } } } } } static void netsalary(){ //formula Net salary = basic salary+new year allowance+marital allowance+cosf of living - EPF for(int h=0;h<2;h++){ if (bsalary[h]<=10000){ nyallowance[h]=2000; } else{ nyallowance[h]=0; } if (bsalary[h]>10000 && bsalary[h]<20000){ nyallowance[h]=3000; } else{ nyallowance[h]=0; } if (bsalary[h]>20000){ nyallowance[h]=5000; } else{ nyallowance[h]=0; } if (marrystatus.equals("Married")){ mrallowance[h]=4000; } else{ mrallowance[h]=0; } epf[h]= bsalary[h]*.4; costol=4500; netsalary[h]=bsalary[h]+nyallowance[h]+mrallowance[h]+costol+epf[h]; } } static void result(){ for(int n=0;n<2;n++){ System.out.println("Employee ID :"+emp[n]); System.out.println("Name :"+name[n]); System.out.println("Date of Birth :"+z[n]); System.out.println("IC Number :"+ic[n]); System.out.println("Appointed Date :"+z1[n]); System.out.println("Working Duration :"+years[n]+"Years"); System.out.println("Position :"+position[n]); System.out.println("Marital Status :"+mstatus[n]); System.out.println("Email :"+email[n]); System.out.println(); System.out.println("Pay Sheet ---------------------------------"); System.out.println("\n"); System.out.println("Basic Salary :"+bsalary[n]); System.out.println("EPF :"+epf[n]); System.out.println("Cost of Living :"+costol); System.out.println("Marital Allowance :"+mrallowance); System.out.println("New Year Allowance :"+nyallowance); System.out.println(); System.out.println("--------------------------------------------"); System.out.println("Netsalary: "+netsalary); System.out.println("--------------------------------------------"); } } }