Hey all,
I can't seem to figure out where this null pointer exception is coming from. I have a Data Access Object that has a getUsers() method that returns an array of user-defined type User. Whenever invoking the method from my jsp it gives me a null pointer exception at the ValidUsers\[i\].setUsername("asdf"); line.
I thought perhaps I wasnt getting a returned row, but the problem error still occurs if I pass it a hard coded string. Here is the code.
public User[] getUsers() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
Connection conn = SQLServerDAOFactory.createConnection();
PreparedStatement psValidUsers = conn.prepareStatement("Select * from tblUsers");
ResultSet rsValidUsers = psValidUsers.executeQuery();
User[] ValidUsers = new User[rsValidUsers.getFetchSize()];
int i = 1;
while (rsValidUsers.next()) {
ValidUsers.setUsername("asdf");
ValidUsers[i].setPassword(rsValidUsers.getString("Password"));
ValidUsers[i].setFirstname(rsValidUsers.getString("Firstname"));
ValidUsers[i].setLastname(rsValidUsers.getString("Lastname"));
ValidUsers[i].setPhone(rsValidUsers.getString("Phone"));
ValidUsers[i].setExtension(rsValidUsers.getString("Extension"));
ValidUsers[i].setFax(rsValidUsers.getString("Fax"));
ValidUsers[i].setIsActive(rsValidUsers.getBoolean("Active"));
ValidUsers[i].setIsContractor(rsValidUsers.getBoolean("Contractor"));
i++;
}
return ValidUsers;
}
I know that null pointer exceptions are hard to pinpoint cause they happen at runtime, but if you guys have a method of debugging then I'm open for it. I'm not familiar with netbeans debugger.