This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post the code of your servlet .

avi sinha
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post the stacktrace too then may be we can help here.

avi sinha
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's on line 60?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it working now?
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Do you have the file in the specified path?
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah you have a very descriptive error trace now.
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It *is* looking there, for a file named "null".

Is there a file named "null" there?
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notice that the request.getAttribute("selected") is returning a null.
THat is why it is looking for a file named null.

Thanks,

Sonia
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic