This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ContextListener is giving me error

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all,
again i am facing problem i am able to run Listener class also the ContextListener is initialised but it is giving me error on Tomcat 6.0 command prompt
Here is my Listener Class Sample.java i am able to compile the code but it is giving java.lang.nullpointer exception at runtime on Tomcat.exe
kindly help me to resolve this issue Is there is problem in my code



 
Marshal
Posts: 67424
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show the error including the stack trace. Otherwise, we're just guessing.
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks the error is coming in Tomcat comand prompt window



this is the error message
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print out the entire stack trace instead of just the error message. Then you'll know exactly in which line of code the exception occurred. You'd do that by "ex.printStrackTrace()".
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess that this points to the line that is #132 in the code above. There's only a single object that could be null, so that makes it pretty easy to find the problem :-)
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your prompt reply but i am not able to figure out the problem , can you tell me the error in my code please help
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tomcat is also printing database values . where is the error i am not able to figure out, kindly help me to resolve this issue



 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have changed your code, so that the problem is now in line 136. What happens in that line? Which object could be null (you know what a NullPointerException is and why it happens, right) ? Why could it be null?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it giving error on this line ??



can you tell me where is my mistake?
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's probably the one. Think about it for a minute, and answer these question: 1) What is a NullPointerException, and why does it happen? 2) Which objects are used in this line of code? 3) Could any of them be null?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply

A null pointer exception happens when you declare (create) a variable, but do not initialize it. An integer is zero by default,
but a non-number variable that doesn't have a value has the value null.Attempting to use a null object generates this exception,
because the program does not know what to do with that object

but i have already declared stmt1 in my code above in my code
and also executeUpdate


i have written the below line because i want to update the rows whose flag are 0 previously are set to 1 after sending the mail
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A null pointer exception happens when you declare (create) a variable, but do not initialize it.



but i have already declared stmt1 in my code above in my code



Compare these two statements carefully, and you'll have your answer.
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks

should i initialise like below statement kindly guilde me i am not able to figure out my mistake .


i have try this also but still it is giving me error

 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Sample.java code is

 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going by your previous post I thought you understood the difference between declaring an object, and initialising it, but apparently not. Post the lines of code where you are 1) declaring the object and 2) initialising the object.
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your guidance i understood instead of writing stmt1 i should put stmt



it get compiled it is not giving error on Tomcat command prompt but it is not sending mail to the user

 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a different issue; please start a new thread and post the information that is relevant to sending mails.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very important: You need to cut down the length of your posts to a minimum. There is no point in posting identical error messages 10 times, or output from loops that doesn't differ. Please edit your previous post and delete all that extraneous material. You can indicate if any of the messages occurred more than once, instead.

I'm confused. You said there was no error. But now there is an error?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the inconvinience cause
after i change the statement below


to new statement



it get compiled but it is not generating proper output instead it is printing only upto this as



means it is not going in the while loop now and not printing value and also not generating mail

and giving me output as




kindly help i am not able to figure out my mistake or error in my code
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems a DB-specific problem that you could ask about in the JDBC forum. If this was my problem I would convert this to a standalone desktop app that does all the DB and mail interaction, and only once I got that to work would I run it in a servlet environment. That would make testing so much easier and quicker, instead of having to start and restart web apps all the time.
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic