aspose file tools*
The moose likes Servlets and the fly likes ContextListener is giving me error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ContextListener is giving me error" Watch "ContextListener is giving me error" New topic
Author

ContextListener is giving me error

Priyanka Dande
Ranch Hand

Joined: May 14, 2012
Posts: 53
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



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Please show the error including the stack trace. Otherwise, we're just guessing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Priyanka Dande
Ranch Hand

Joined: May 14, 2012
Posts: 53
thanks the error is coming in Tomcat comand prompt window



this is the error message
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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()".


Ping & DNS - my free Android networking tools app
Priyanka Dande
Ranch Hand

Joined: May 14, 2012
Posts: 53
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
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

Joined: May 14, 2012
Posts: 53
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
is it giving error on this line ??



can you tell me where is my mistake?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
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

Joined: May 14, 2012
Posts: 53
My Sample.java code is

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
That is a different issue; please start a new thread and post the information that is relevant to sending mails.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 14, 2012
Posts: 53
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ContextListener is giving me error