Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

null pointer exception

Status
Not open for further replies.

abyinsydney

Programmer
Feb 17, 2004
99
AU
folks
how do you catch null pointer exception.ie.


what is the hierarchy for catching null pointer exception

in try castch block


aby
 
Code:
try {
  //somestuff
} catch (NullPointerException npe) {
  //do something
  npe.printStackTrace(System.err);
}

or :

try {
  //somestuff
} catch (Exception e) {
  //do something
  e.printStackTrace(System.err);
}
 
sedj
i'm trying to catch null pointer exception but unable to catch it any comments
 
have you tried :

try {
//somestuff
} catch (Exception e) {
//do something
e.printStackTrace(System.err);
}
??
 
i'M GETTING TH EFOLOWING ERROR WHEN EXECUTING THE RESULT SET AND THE ERROR IS GETTING PRINTIED ON MY SCREEN I DO NOT WANT IT TOBE PRINTED ON MY SCREEN BUT CATCH IT THRO SYSTEM.OUT .PRINTLN

i HAVE TRIED ALL EXCEPTIONS BUT NOTHINGS SEEMS TO WORK


PLEASE HELP SEDJ
ABY
500 Internal Server Error
/archiving/archiving/jsp/transactions10.jsp:

java.lang.NullPointerException
at jrun__archiving__jsp__transactions12ejsp20._jspService(jrun__archiving__jsp__transactions12ejsp20.java:421)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.jsp.JRunPageContext.forward(../jsp/JRunPageContext.java:298)
at jrun__archiving__jsp__transactions112ejsp21._jspService(jrun__archiving__jsp__transactions112ejsp21.java:117)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.jsp.JRunPageContext.forward(../jsp/JRunPageContext.java:298)
at jrun__archiving__jsp__transactions102ejsp21._jspService(jrun__archiving__jsp__transactions102ejsp21.java:113)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:115)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)

 
try {
//somestuff
} catch (Exception e) {
//do something
e.printStackTrace(System.out);
}

using System.out as the parameter to the printStackTrace() method will cause the stack trace to print in standard output as if you had used System.out.println();


 
ploy guy

The exception is getting printed on the screen i do not want itto be printed on the screen it occupies the whole page i want to catchit .there are no excptions method to catch it i have tried all the posssibilities any suggestions


aby
 
greetings folkshow do i accomplish the fact that when your result set returns null from the data base you redirect your page to a different jsp

i HAVE TRIED <jsp:forward page="login.jsp"/>

it does not work .could any body helpme inthis

i'm using my sql and jsp

aby
 
Hi,

<%
if(null == resultSet){
%>
<jsp:forward page="login.jsp"/>
<%
}
%>

Is this what u tried ?

Cheers
Venu
 
yes venu that what i have tried but i'm not getting redirected to login.jsp.get the folowing error

h1>500 Internal Server Error</h1>
<PRE>
<B>/archiving/archiving/jsp/transactions10.jsp:</B>

java.lang.NullPointerException
at jrun__archiving__jsp__transactions12ejsp20._jspService(jrun__archiving__jsp__transactions12ejsp20.java:319)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.jsp.JRunPageContext.forward(../jsp/JRunPageContext.java:298)
at jrun__archiving__jsp__transactions112ejsp21._jspService(jrun__archiving__jsp__transactions112ejsp21.java:120)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.jsp.JRunPageContext.forward(../jsp/JRunPageContext.java:298)
at jrun__archiving__jsp__transactions102ejsp21._jspService(jrun__archiving__jsp__transactions102ejsp21.java:132)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:39)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:228)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:196)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:115)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)

</PRE>
 
Just add some debug like System.err.println("here") to see where you are going wrong ... its how everybody else works out where their NPE's are ...
 
sedj
i've debugged the problem my problem is if the result set returns a null value.i'm not able to redirect it to a different page.

if it does not returns a null value the code works fine.

does the resultset has to be printed then redirected to a different page ???


aby

 
Try something like this :

Code:
...
ResultSet rs = ...

boolean hasData = rs.next();

if (hasData) {
  // do something
} else {
  // redirect
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top