null pointer in a method
Hi
i have a switchcase statement in my code that, when selected, this method is called. this method (shown below) finds a person in an array of clients (based on the name the user gives) then displays their info. the problem is that it comes up with a null pointer exception if the array is empty and i thought i had tackled this problem by the very first if statement, buyt this statement isnt noticed by the program? any help as to y this is so would be appreciated. PS: i have commented the chunk out as i have not yet written the code for the accounts bit of the task
publicstaticvoid displayClient (Client[]c)
{
String name;
int total=0, poss=0, choice;
if (c.length == 0)
{
System.out.println("no clients exist");
}
else
{
System.out.print("Please enter the name of the client you wish to show: ");
name = console.next();
for (int i=0;i<total;i++)
{
if ((c[i].getName()) == name)
{
poss = i;
}
}
}
System.out.println("name: "+(c[poss].getName()));
System.out.println("Resident: "+(c[poss].getResident()));
System.out.println("Gross Salary (per week): "+(c[poss].getWeeklyGrossSalary()));
System.out.println("Net Salary (per week): "+(c[poss].getWeeklyNetSalary()));
System.out.println("tax (per week): "+(c[poss].getWeeklyTax()));
System.out.println("medicare (per week): "+(c[poss].getWeeklyMedicare()));
System.out.println("Expenses: "+(c[poss].getWeeklyExpenses()));
//if (a.length=0)
//{
//System.out.println("No Accounts");
//}
// else
// {
// showAccountSelection();
// choice = console.nextInt();
//while(choice != 9)
//{
// switch(choice)
// {
//case 1:
// c.addAccount();
// break;
//case 2:
//c.deleteAccount();
//break;
//case 3:
// c.displayAccount();
// break;
//case 9:
//
// break;
// default: System.out.println("Invalid Selection");
//}//end switch
//showAccountSelection();
// choice = console.nextInt();
//
// }
//}
}
>

