Unhandled NullPointerException

I keep getting Unhandled NullPointerException although the loginID is not null.

public Secuser[] getBulkUserLoginID(String loginID)

{

Secuser[] user =null;

try

{

String sql ="SELECT * FROM " + Constant.DB_REPORTCONFIG+".secuser s WHERE s.parent_login like '" + loginID +"'";

System.out.println("sql >> " + sql);

ArrayList rows = (ArrayList) dao.query(sql,Constant.DEFAULT_DATASOURCE_NAME);

if(rows !=null && rows.size() > 0)

{

user =new Secuser[rows.size()];

for(int i = 0 ; i < rows.size() ; i++)

{

Object[] cols = (Object[])rows.get(i);

System.out.println("loginID : " + col[0]);// output : loginID : isentric

user[i].setLoginID(String.valueOf(cols[0]));// this line throws NullPointerException

}

}

}

catch(NullPointerException npe)

{

npe.printStackTrace();

}

finally

{

return user;

}

}

[1865 byte] By [shamexa] at [2007-11-27 9:06:41]
# 1
I keep getting Unhandled NullPointerException although the loginID is not null.But, user[ i ] is null.
johndjra at 2007-7-12 21:42:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Then , how should I initialize Secuser[] user ? Any idea ?
shamexa at 2007-7-12 21:42:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

Well I really wouldn't know, as that depends entirely on the Secuser class. (No, I don't want you to post the code for that class).

You allocated an array by doing

user = new Secuser[rows.size()];

But all that gives you is a array of null references. You still need to create

a Secuser object to put in user[0] (or 1 or whatever).

Somewhere in that loop there should be a call the Secuser's constructor and I see none.

johndjra at 2007-7-12 21:42:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
I guess have found the way to fix the problem. Thank you for your time
shamexa at 2007-7-12 21:42:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...