ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: Problem with nullpoiterException.
Date Wed, 25 Jul 2007 10:03:56 GMT
Hi,

Why did you comment the initalization of rowBeheer[i]? That blows stuff
up... Also, why are you performing beanfield copying between Beheer and
RowBeheer, why not directly return the Beheer class?

No offense, but these are all basic Java programming questions/problems,
try following some tutorials/guides first...

Niels

-----Original Message-----
From: Jdev [mailto:jdev02@telenet.be] 
Sent: woensdag 25 juli 2007 10:20
To: user-java@ibatis.apache.org
Subject: RE: Problem with nullpoiterException.

Correct, I have adapted it with this  

rowBeheer = new RowBeheer[resultList.size()]; 


Now I get still the same error, nullpoiterexception
In my stacktrace i get a error on line 
rowBeheer[i].setReferentienummer(beheer.getReferentienummer()); 


public RowBeheer[] readBeheerList1(String ondnr) { 

RowBeheer[] rowBeheer = null; 

try { 
dao.BeheerDAO beheerDao = (dao.BeheerDAO) 
DaoManagerRequester.getDaoManager().getDao(dao.BeheerDAO.class); 
model.BeheerExample beheerExample = new model.BeheerExample(); 
beheerExample.createCriteria().andReferentienummerLike(likesleutel); 
List resultList = beheerDao.selectByExample(beheerExample); 

if (resultList.size() > 0) { 
rowBeheer = new RowBeheer[resultList.size()]; 
for(int i = 0; i < resultList.size(); i++) { 
// rowBeheer[i] = new RowBeheer(); Comment
model.Beheer beheer = (model.Beheer) resultList.get(i); 
rowBeheer[i].setReferentienummer(beheer.getReferentienummer()); 
rowBeheer[i].setVolgnr(beheer.getVolgnr()); 
rowBeheer[i].setRowdatumbegin(String.valueOf(beheer.getRowdatumbegin()))
; 
rowBeheer[i].setRowdatumeinde(String.valueOf(beheer.getRowdatumeinde()))
; 
rowBeheer[i].setKantoorcode(beheer.getKantoorcode()); 
rowBeheer[i].setDossierstatus(beheer.getDossierstatus()); 
return rowBeheer; 
} 
} 
} catch (Exception e) { 
e.printStackTrace(); 
} 
return null; 
} 

Greetz.





>Hello, 
>
>As Ashok said on Sunday, the RowBeheer[] array is never initialized. 
>When you try to assign a value into an uninitialized array, you get a
null >pointer exception. 
>
>You need something like this after you get the resultList back from the
>selectByExample call: 
>
>rowBeheer = new RowBeheer[resultList.size()]; 
>
>Cheers, 
>Chris 
>
>On Tue, 2007-07-24 at 18:22 +0200, Jdev wrote: 
> In my stacktrace I get an error on the line: 
> 
> rowBeheer[i] = new RowBeheer(); 
> 
> In my logfile I get this as result = 
> 
> Error resultList : Cause : java.lang.NullPointerException 
> 
> I think that I have gone wrong somewhere; this block of code is loaded

> only in the memory and is not visible for the user. The systems looks 
> up the user of he has permission to access the system. I think I do 
> something wrong with [] 
> 
> 
> 
> public RowBeheer[] readBeheerList1(String ondnr) { 
> 
> RowBeheer[] rowBeheer = null; 
> 
> try { 
> 
> dao.BeheerDAO beheerDao = (dao.BeheerDAO) 
> 
> DaoManagerRequester.getDaoManager().getDao(dao.BeheerDAO.class); 
> 
> model.BeheerExample beheerExample = new model.BeheerExample(); 
> 
> beheerExample.createCriteria().andReferentienummerLike(likesleutel); 
> 
> List resultList = beheerDao.selectByExample(beheerExample); 
> 
> if (resultList.size() > 0) { 
> 
> for(int i = 0; i < resultList.size(); i++) { 
> 
> rowBeheer[i] = new RowBeheer(); error in the in stacktrace 
> 
> model.Beheer beheer = (model.Beheer) resultList.get(i); 
> 
> rowBeheer[i].setReferentienummer(beheer.getReferentienummer()); 
> 
> rowBeheer[i].setVolgnr(beheer.getVolgnr()); 
> 
> 
> rowBeheer[i].setRowdatumbegin(String.valueOf(beheer.getRowdatumbegin()

> )); 
> 
> 
> rowBeheer[i].setRowdatumeinde(String.valueOf(beheer.getRowdatumeinde()

> )); 
> 
> rowBeheer[i].setKantoorcode(beheer.getKantoorcode()); 
> 
> rowBeheer[i].setDossierstatus(beheer.getDossierstatus()); 
> 
> return rowBeheer; 
> 
> } 
> 
> } 
> 
> } catch (Exception e) { 
> 
> e.printStackTrace(); 
> 
> } 
> 
> return null; 
> 
> } 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -----Original Message----- 
> 
> From: Richard Yee [mailto:ryee@cruzio.com] 
> 
> Sent: zondag 22 juli 2007 21:46 
> 
> To: user-java@ibatis.apache.org 
> 
> Subject: Re: Problem with nullpointerException. 
> 
> What line is it occurring on? 
> 
> Did you initialize the DaoManager with the sqlMapConfig file? 
> 
> This code: 
> 
> dao.BeheerDAO beheerDao = (dao.BeheerDAO) 
> 
> DaoManagerRequester.getDaoManager().getDao(dao.BeheerDAO.class); 
> 
> could be put somewhere else b/c it only has to run once. You could 
> store 
> 
> the DAO in application scope. 
> 
> -Richard 
> 
> Davy wrote: 
> 
> > 
> 
> > Can someone explain me how I get the code mentioned below running? 
> 
> > 
> 
> > The problem is that it concerns a list and I don't know correct how 
> I 
> 
> > get it to work, the code that I developed gives me each time a 
> 
> > nullpointerexception when I run it. 
> 
> > 
> 
> > Can someone give me some information about what I do wrong? 
> 
> > 
> 
> > public RowBeheer[] readBeheerList1(String ondnr) { 
> 
> > 
> 
> > RowBeheer[] rowBeheer = null; 
> 
> > 
> 
> > try { 
> 
> > 
> 
> > dao.BeheerDAO beheerDao = (dao.BeheerDAO) 
> 
> > DaoManagerRequester.getDaoManager().getDao(dao.BeheerDAO.class); 
> 
> > 
> 
> > model.BeheerExample beheerExample = new model.BeheerExample(); 
> 
> > 
> 
> > beheerExample.createCriteria().andReferentienummerLike(likesleutel);

> 
> > 
> 
> > List resultList = beheerDao.selectByExample(beheerExample); 
> 
> > 
> 
> > if (resultList.size() > 0) { 
> 
> > 
> 
> > for(int i = 0; i < resultList.size(); i++) { 
> 
> > 
> 
> > rowBeheer[i] = new RowBeheer(); 
> 
> > 
> 
> > model.Beheer beheer = (model.Beheer) resultList.get(i); 
> 
> > 
> 
> > rowBeheer[i].setReferentienummer(beheer.getReferentienummer()); 
> 
> > 
> 
> > rowBeheer[i].setVolgnr(beheer.getVolgnr()); 
> 
> > 
> 
> > 
> rowBeheer[i].setRowdatumbegin(String.valueOf(beheer.getRowdatumbegin()

> )); 
> 
> > 
> 
> > 
> rowBeheer[i].setRowdatumeinde(String.valueOf(beheer.getRowdatumeinde()

> )); 
> 
> > 
> 
> > rowBeheer[i].setKantoorcode(beheer.getKantoorcode()); 
> 
> > 
> 
> > rowBeheer[i].setDossierstatus(beheer.getDossierstatus()); 
> 
> > 
> 
> > return rowBeheer; 
> 
> > 
> 
> > } 
> 
> > 
> 
> > } 
> 
> > 
> 
> > } catch (Exception e) { 
> 
> > 
> 
> > e.printStackTrace(); 
> 
> > 
> 
> > } 
> 
> > 
> 
> > return null; 
> 
> > 
> 
> > } 
> 
> > 
> 





Mime
View raw message