Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/03/2009, 08:57
Pelirr
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 5 meses
Puntos: 1
Problema coger elementos array en servlet

Hola, quiero en un servlet, crear unas listas de tipo dto, donde guardar varios dto y luego poder acceder a sus campos para mostrarlos depués en la página jsp. Pero cuando llega a "accountint[i] = accounts.getAccountnumber();" me dá un error java.lang.NullPointerException, y la verdad no lo comprendo, creo que lo que le estoy diciendo es que me meta en accountint[i] (que es el elemento i de la lista accountint) el valor del campo Accountnumber de mi dto accounts, que no debería estar vacío, porque se supone que debe contener el elemento i de la lista accountlist. Parte del servlet es:

...
public class DarBajaClienteServlet extends HttpServlet {

private boolean initialized;
private ArrayList initErrors;
private HttpServlet servlet;
private clientsFacadeHome clientHome;
private accountsFacadeHome accountHome;
private balanceFacadeHome balanceHome;
public String RESULT_URL, nif, theJNDIName, name, lastname1, lastname2,address,birthdate, phone, index, creationdate[], accounttype[], account[],concept[], conceptdate[], key[], office[], amount[], amountbalance[];
private int phoneint, indexint, accountint[], keyint[], officeint[], amountint[], amountbalanceint[];
private ArrayList errors, balancelist;
private ArrayList<accountsDto> accountlist;

...

public void populate(HttpServletRequest theRequest) throws NamingException{
nif=theRequest.getParameter("nif");
clientsDto clients = new clientsDto();
accountsDto accounts = new accountsDto();
balanceDto balance = new balanceDto();

Context ctx = getInitialContext();

Object homeclient = ctx.lookup("SCajaElenaClientsEjb");
clientHome = (clientsFacadeHome)homeclient;
clientsFacade clientmethod = null;

Object homeaccount = ctx.lookup("SCajaElenaEjb");
accountHome = (accountsFacadeHome)homeaccount;
accountsFacade accountmethod = null;

Object homebalance = ctx.lookup("SCajaElenaBalanceEjb");
balanceHome = (balanceFacadeHome)homebalance;
balanceFacade balancemethod = null;

try {
try {
clientmethod = clientHome.create();
accountmethod = accountHome.create();
balancemethod = balanceHome.create();

try {
clients.setNif(nif);
clients = clientmethod.ReadByNif(clients);

if (clients!=null)
{
name = clients.getName();
lastname1 = clients.getFirstlastname();
lastname2 = clients.getSecondlastname();
address = clients.getAdress();
birthdate = clients.getBirthday();
phoneint = clients.getTelephone();
indexint = clients.getIndex();

phone = Integer.toString(phoneint);
index = Integer.toString(indexint);

theRequest.setAttribute("name", name);
theRequest.setAttribute("lastname1", lastname1);
theRequest.setAttribute("lastname2", lastname2);
theRequest.setAttribute("address", address);
theRequest.setAttribute("birthdate", birthdate);
theRequest.setAttribute("phone", phone);
theRequest.setAttribute("index", index);

accounts.setNif(nif);
accounts = accountmethod.ReadByNif(accounts);
if (accounts!=null)
{
accountlist = accountmethod.ReadAllByNif(accounts, nif);
System.out.println("Despues de la lista account");
//Y con el for, lo recorro y lo voy modificando
for (int i=0;i<accountlist.size(); i++)
{
accounts = accountlist.get(i);
System.out.println("coge cada miembro de lista");
accountint[i] = accounts.getAccountnumber();
keyint[i]=accounts.getAccountkey();
accounttype[i]=accounts.getAccounttype();
creationdate[i] = accounts.getCreationdate();
officeint[i] = accounts.getOffice();

key[i] = Integer.toString(keyint[i]);
office[i] = Integer.toString(officeint[i]);
account[i]= Integer.toString(accountint[i]);

theRequest.setAttribute("account["+i+"]", account[i]);
theRequest.setAttribute("accounttype["+i+"]", accounttype[i]);
theRequest.setAttribute("creationdate["+i+"]", creationdate[i]);
theRequest.setAttribute("key["+i+"]", key[i]);
theRequest.setAttribute("office["+i+"]", office[i]);

balance.setAccountnumber(accounts.getAccountnumber ());
balance = balancemethod.ReadByAccount(balance);
if (balance!=null)
{
balancelist = balancemethod.ReadByNumber(balance, accounts.getAccountnumber());
System.out.println("después lista balance");
for(int j=0; j<balancelist.size();j++)
{
balance = (balanceDto) balancelist.get(j);
System.out.println("coge miembro lista balance");
amountint[j] = balance.getAmount();
amountbalanceint[j] = balance.getAmountbalance();
concept[j] = balance.getConcept();
conceptdate[j] = balance.getConceptdate();

amount[j] = Integer.toString(amountint[j]);
amountbalance[j] = Integer.toString(amountbalanceint[j]);

theRequest.setAttribute("amount["+j+"]",amount[j]);
theRequest.setAttribute("amountbalance["+j+"]",amountbalance[j]);
theRequest.setAttribute("concept["+j+"]",concept[j]);
theRequest.setAttribute("conceptdate["+j+"]",conceptdate[j]);
}
}
else
{
System.out.println("No hay movimientos");
}
}
}
else
{
System.out.println("No hay cuentas");
}
RESULT_URL = "/JSP/ConfirmBajaCliente.jsp";
}
else
{
RESULT_URL = "/HTML/3.BajaCliente/NoExisteCliente-Elim.html";
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

....

Lo que en realidad busco es poder mostrar los valores de esas listas posteriormente en una página jsp. A lo mejor estoy complicándolo mucho. ¿Podéis echarme un cable? Muchas gracias, un saludo