Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NPE with if

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've this form that displays my blog's content inside a textarea; the form also has two submit buttons, one for update and the other for delete.
inside my servlet i've this code:

if i try with just one if (i mean the other if is commented) all works, but if i have both ifs uncommented, i get that NPE

how can i solve this?

TiA
 
Gareth Western
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume the NPE is because the parameter being passed is EITHER "editarBlog" OR "eliminarBlog", depending on what action you are doing?

If so, the easiest way around the problem is to check that the "editar" and "eliminar" variables are not null before checking for equality.

E.g.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A better style is to use the String first and ignore the problem with nulls.
Also, be wary of SQL that doesn't use PreparedStatements. Your code is open to SQL injection that could allow someone to do whatever they want to your data.



Dave
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that works, ty!
as to prepared statement, i'll work on that
thank you both
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:
[CODE]
try {
//if (editar.equals("Editar")) {
//access.executaUpdate(sqlActualizar);
//getServletContext().getRequestDispatcher("/EditarAvulsas").forward(request, response);
//}


editar is null or access is null , path /EditarAvulsas doesnot map to a resource.
try putting the code in a catch block of Exception and look at the exception dot printStackTrace() methods output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic