hi friends,
seems as if though this null pointers wont let me go peacefully home!!!!
i have a jsp page where i do a get attribute like this--->
[HTML]<%String s24=(String) request.getAttribute("s24"); %>[/HTML]
and to retrieve the value i do some thing like this--->
[HTML]<%=s24.substring(0,9) %>[/HTML]
but the method substring(0,9) is giving me a null pointer exception. have can i avoid or rather eliminate this exception/error?? please guide me regarding this:).
regards,
ajos
11 7029
hi friends,
seems as if though this null pointers wont let me go peacefully home!!!!
i have a jsp page where i do a get attribute like this--->
[HTML]<%String s24=(String) request.getAttribute("s24"); %>[/HTML]
and to retrieve the value i do some thing like this--->
[HTML]<%=s24.substring(0,9) %>[/HTML]
but the method substring(0,9) is giving me a null pointer exception. have can i avoid or rather eliminate this exception/error?? please guide me regarding this:).
regards,
ajos
The string s24 is null. That means the attribute called s24 was never passed to the JSP. Where is it supposed to come from? A servlet?
The string s24 is null. That means the attribute called s24 was never passed to the JSP. Where is it supposed to come from? A servlet?
hi r035198x,
thanks for your reply yet again.wat i did was in my servlet---> -
s24 = resultset.getString(11);
-
httpservletrequest.setAttribute("s24", s24);
-
and in my jsp page the method i mentioned above...so is it not supposed to work if i do a s24.substring(0,9)??
regards,
ajos
hi r035198x,
thanks for your reply yet again.wat i did was in my servlet---> -
s24 = resultset.getString(11);
-
httpservletrequest.setAttribute("s24", s24);
-
and in my jsp page the method i mentioned above...so is it not supposed to work if i do a s24.substring(0,9)??
regards,
ajos
Have a try this... -
s24 = resultset.getString(11);
-
System.out.println(s24); //it must output NULL
-
Debasis Jana
Have a try this... -
s24 = resultset.getString(11);
-
System.out.println(s24); //it must output NULL
-
Debasis Jana
hi Debasis,
where am i supposed to write S.O.Pln ?i want to output this in my jsp page. i tried doing
[HTML]
<%=s24>
[/HTML]
thats printing me null values, but i want to view the substring value instead.
:)
regards,
ajos
hi r035198x,
thanks for your reply yet again.wat i did was in my servlet---> -
s24 = resultset.getString(11);
-
httpservletrequest.setAttribute("s24", s24);
-
and in my jsp page the method i mentioned above...so is it not supposed to work if i do a s24.substring(0,9)??
regards,
ajos
You should understand why the exception is thrown. s24.substring(0, 9) throws a null pointer only if s24 is null. Now looking at your code there is no guarantee that s24 is not null.
Either resultset.getString(11) itself returned null or you did not include the request/response arguments when you opened the JSP from the servlet.
You should understand why the exception thrown. s24.substring(0, 9) throws a null pointer only if s24 is null. Now looking at your code there is no guarantee that s24 is not null.
Either resultset.getString(11) itself returned null or you did not include the request/response argumemnts when you opened the JSP from the servlet.
actually even with <%=s24> i gut a null value coz the query didnt match with requirement, my question is even if with the .substring() method i should get a null value in my results page isnt it? correct me if i am wrong.if thats not how it works then wat changes shud i do??
regards :),
ajos
actually even with <%=s24> i gut a null value coz the query didnt match with requirement, my question is even if with the .substring() method i should get a null value in my results page isnt it? correct me if i am wrong.if thats not how it works then wat changes shud i do??
regards :),
ajos
If you try to derefence null you will get a nullpointer exception so s24.substring(0, 9) does not return null but instead throws a nullpointer exception when s24 is null.
What you should do to make it work depends on how you want it to work. What do you want to do if the value returned from the database is null?
actually even with <%=s24> i gut a null value coz the query didnt match with requirement, my question is even if with the .substring() method i should get a null value in my results page isnt it? correct me if i am wrong.if thats not how it works then wat changes shud i do??
regards :),
ajos
Then try it... -
try{
-
}
-
catch(Exception)
-
{
-
//do nothing
-
}
-
//here the code execution will be normal
-
Debasis Jana
Then try it... -
try{
-
}
-
catch(Exception)
-
{
-
//do nothing
-
}
-
//here the code execution will be normal
-
Debasis Jana
Don't do that. That will hide all the exceptions rather than handle them.
If you try to derefence null you will get a nullpointer exception so s24.substring(0, 9) does not return null but instead throws a nullpointer exception when s24 is null.
What you should do to make it work depends on how you want it to work. What do you want to do if the value returned from the database is null?
with the form beans around even if the result doesnt match with the query we tend to get null as the result...thats wat i want to display if the result of the substring is null.is it possible?
regards,
ajos
with the form beans around even if the result doesnt match with the query we tend to get null as the result...thats wat i want to display if the result of the substring is null.is it possible?
regards,
ajos
That's what the if statement is for. - if(s24 != null) {
-
valueToDisplay = s24.substring(0, 9);
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jennifer johnson |
last post by:
Hello All,
I appreciate anyone's assistance. I wanted to validate user customizable
field values so I changed my JSP page so that the form action would post
existing form - action=<%=...
|
by: Mark |
last post by:
Hi,
I'm writing user controls with custom events.
I have a parent custom event that exposes some abstract methods and
some custom events.
I have also created some new user controls that...
|
by: Tony Cheng |
last post by:
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&&...
|
by: chramprasad |
last post by:
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
...
|
by: zahidkhan |
last post by:
Hi All,
Plz help me if you can.....
I have a program something like this
int main(int argc,char* argv)
{
try
{
int* p = NULL;
|
by: MRamaLakshmi |
last post by:
hi,
I am developing an application using Java Applet which will be uploading files.
Its throwing Null Pointer exception while detecting the proxy when we are trying to load the applet using Java6....
|
by: bansalrichaacc |
last post by:
In The Following Code I am Getting Null Pointer Exception
try{
ClientBean clientInfo = clientManager.getClientList();
System.out.println("richa2"+clientInfo);
if (clientInfo != null )...
|
by: iamdennisthomas |
last post by:
Hi Guys i was developing a action servlet which is actulally getting the data from a form and putting it in the db but while executing i am getting a null pointer exception
/*
* Generated by...
|
by: swathi amireddy |
last post by:
Currently im trying to migrate a project from .net 1.1 to 2.0.While running the application its giving an exception for the below code while doing the update operation:
protected void...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |