K
kath
hi,
1. I have a stateless session bean(TestBean)
2. I have helper classes(TestHelper, which implements operations like
db connectivity, retrieve/update/insert data from/to db)
3. I have a model class(say, TestModel), which is a complext
datastructure. I has attributes(members) like (String, ArrayLList)
Now i have a business method in bean(TestBean), say getSomthing().
when this business method is called it creates an object of the helper
class(TestHelper), and calls its member function(say,
dbGetSomething()). Where, dbGetSomething returns array of my model
class(TestModel[]).
Now i will show, psuedo code of the above explained,
class TestHelper
{
public TestHelper(){
// establishes a connection to db, and works fine
...
}
public TestModel[] dbGetSomething(){
ArrayList list = new ArrayList();
// Create a prepare statement, for SELECT query
// execute above prepare statement.
while(rs.next()){
TestModel t = new TestModel();
// set attributes of class from record set.
...
list.add(t);
}
TestModel[] model = new TestModel[ list.size() ];
list.toArray(model);
return model;
}
}
Now this function works fine when i have some results for the SELECT
query. But NullPointerException otherwise.
So, i did which replaces code after while statement like,
if ( list.isEmpty() ){
TestModel temp = new TestModel();
TestModel tModel = new TestModel[1];
tModel[0] = temp;
return tModel;
}else{
TestModel[] model = new TestModel[ list.size() ];
list.toArray(model);
return model;
}
But still i get NullPointerException...
can any one pls explain,
Why im getting NullPointerException, even though i returning a value
of object-reference, which i have created.
thanks in advance,
kath.
1. I have a stateless session bean(TestBean)
2. I have helper classes(TestHelper, which implements operations like
db connectivity, retrieve/update/insert data from/to db)
3. I have a model class(say, TestModel), which is a complext
datastructure. I has attributes(members) like (String, ArrayLList)
Now i have a business method in bean(TestBean), say getSomthing().
when this business method is called it creates an object of the helper
class(TestHelper), and calls its member function(say,
dbGetSomething()). Where, dbGetSomething returns array of my model
class(TestModel[]).
Now i will show, psuedo code of the above explained,
class TestHelper
{
public TestHelper(){
// establishes a connection to db, and works fine
...
}
public TestModel[] dbGetSomething(){
ArrayList list = new ArrayList();
// Create a prepare statement, for SELECT query
// execute above prepare statement.
while(rs.next()){
TestModel t = new TestModel();
// set attributes of class from record set.
...
list.add(t);
}
TestModel[] model = new TestModel[ list.size() ];
list.toArray(model);
return model;
}
}
Now this function works fine when i have some results for the SELECT
query. But NullPointerException otherwise.
So, i did which replaces code after while statement like,
if ( list.isEmpty() ){
TestModel temp = new TestModel();
TestModel tModel = new TestModel[1];
tModel[0] = temp;
return tModel;
}else{
TestModel[] model = new TestModel[ list.size() ];
list.toArray(model);
return model;
}
But still i get NullPointerException...
can any one pls explain,
Why im getting NullPointerException, even though i returning a value
of object-reference, which i have created.
thanks in advance,
kath.