wood burning stoves 2.0*
The moose likes Servlets and the fly likes NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I have a jsf application in which on the first page, the user is allowed to select a file. In the action of that component
the selected file is set in the request as an attribute, and the page is redirected to a servlet. In the servlet,
i do a request.getAttribute for the file name. But I am getting a npe when the servlet tries to access the filename.
Can someone tell me what I am missing. The web.xml servlet mapping does not have any attribute. I thought
the mapping was only for context params and init params.
THanks,

Sonia
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

please post the code of your servlet .

avi sinha


SCJP 5.0 SCWCD 5.0
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

please post the stacktrace too then may be we can help here.

avi sinha
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137


maybe it has something to do with the way I am redirecting?

avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

hello sonia ,
i think i can't give you a good suggestion for this problem. just wait for sometime , perhaps somebody else will guide you about this.
my apology

avi sinha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

So what's on line 60?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185


Are you sure you have this attribute set before this call? If not change this to request.getParameter("selected")

Thanks,
Srikkanth
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
To answer your question
What is on line 60
:
I changed my code so I am not sure what was on line 60 but I think it was:



Thanks,

Sonia
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Is it working now?
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
no; i am not sure what you mean. if i set an attribute how can i get a parameter?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Attributes and parameters have nothing whatsoever to do with one another.

A call to getParameter cannot create an NPE. Until you find out what line is causing the issue, abandon all hope of solving this.
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185


Do you have the file in the specified path?
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

Srikkanth Mohanasundaram wrote:

Do you have the file in the specified path?


i think unavailability of file can't lead to a NullPointerException here.

avi sinha
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Yes you are right
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I did not know where it was looking for the file, so I made the following change to the servlet code:




Now I get the following error: here is the stacktrace
">
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Yeah you have a very descriptive error trace now.
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
yes, but the file is there in that location. WHere is it looking? It should be looking in
c:/downloads/

Thanks,

Sonia
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It *is* looking there, for a file named "null".

Is there a file named "null" there?
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Notice that the request.getAttribute("selected") is returning a null.
THat is why it is looking for a file named null.

Thanks,

Sonia
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NullPointerException