rcmb
asked on
trouble converting string to integer
For some reason I cannot find a solution that works for this senario
Here goes
Integer grpTypeID = null;
//request.getParameter is passed from a form
if(request.getParameter("g rpTypeID") != null){
grpTypeID = new Integer(request.getParamet er("grpTyp eID"));
//this is where I am confused -- I have tried Integer.parseInt but it does not work because grpTypeID is an
//Integer not an Int
} else {
grpTypeID = null;
}
Now this is where I cannot get a result -- e.g. grpTypeName is never returned
if(grpTypeID == grpTypeDTO.getGroup_TypeID ()){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
I cannot get this statement to return a TRUE --
grpTypeDTO.getGroup_TypeID is an Integer
Any ideas on what I can do to get the if statement to return a TRUE if the values equal each other?
Thanks in advance,
RCMB
Here goes
Integer grpTypeID = null;
//request.getParameter is passed from a form
if(request.getParameter("g
grpTypeID = new Integer(request.getParamet
//this is where I am confused -- I have tried Integer.parseInt but it does not work because grpTypeID is an
//Integer not an Int
} else {
grpTypeID = null;
}
Now this is where I cannot get a result -- e.g. grpTypeName is never returned
if(grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeName = grpTypeDTO.getGrpTypeName(
}
I cannot get this statement to return a TRUE --
grpTypeDTO.getGroup_TypeID
Any ideas on what I can do to get the if statement to return a TRUE if the values equal each other?
Thanks in advance,
RCMB
You should use equals because Integer is not primitive.
Regards
Dave
Regards
Dave
or alternatively,
if(grpTypeID.equals(grpTyp eDTO.getGr oup_TypeID ())){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
Regards
Dave
if(grpTypeID.equals(grpTyp
grpTypeName = grpTypeDTO.getGrpTypeName(
}
Regards
Dave
Dave
You are right, but why the && part?
Do just:
if(grpTypeID.equals(grpTyp eDTO.getGr oup_TypeID ())){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
You are right, but why the && part?
Do just:
if(grpTypeID.equals(grpTyp
grpTypeName = grpTypeDTO.getGrpTypeName(
}
Ok, you fixed it :-)
Hi,
If you want to use "==" then do it this way.
int grpTypeID; // Default to 0
if(request.getParameter("g rpTypeID") != null){
grpTypeID = new Integer(request.getParamet er("grpTyp eID").intV alue());
} else {
grpTypeID = 0;
}
Now this is where I cannot get a result -- e.g. grpTypeName is never returned
if(grpTypeID == grpTypeDTO.getGroup_TypeID ()){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
I hope that helps.
Regards
Dave
If you want to use "==" then do it this way.
int grpTypeID; // Default to 0
if(request.getParameter("g
grpTypeID = new Integer(request.getParamet
} else {
grpTypeID = 0;
}
Now this is where I cannot get a result -- e.g. grpTypeName is never returned
if(grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeName = grpTypeDTO.getGrpTypeName(
}
I hope that helps.
Regards
Dave
Hi aozarov,
Yes, I created a mistake :).
Regards
Dave
Yes, I created a mistake :).
Regards
Dave
ASKER
suprapto45
did not work -- no errors but still will not return a match.
Tried three methods
grpTypeID == grpTypeDTO.getGroup_TypeID () && grpTypeID.equals(grpTypeDT O.getGroup _TypeID()
grpTypeID == grpTypeDTO.getGroup_TypeID ()
grpTypeID.equals(grpTypeDT O.getGroup _TypeID()
Still no luck
did not work -- no errors but still will not return a match.
Tried three methods
grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeID.equals(grpTypeDT
Still no luck
>> grpTypeID = new Integer(request.getParamet er("grpTyp eID").intV alue());
Or just do:
grpTypeID = Integer.parseInt(request.g etParamete r("grpType ID"));
Note, that in this case you will need to make grpTypeDTO.getGroup_TypeID () return int instead of Integer as well.
Or just do:
grpTypeID = Integer.parseInt(request.g
Note, that in this case you will need to make grpTypeDTO.getGroup_TypeID
Printout the values before the comparision.
The latters options should work for you.
The latters options should work for you.
Hi,
What does it return of grpTypeDTO.getGroup_TypeID ()? Is it Integer or int?
if it is Integer, then you can return TRUE if you have
Integer grpTypeID = null;
if(request.getParameter("g rpTypeID") != null){
grpTypeID = new Integer(request.getParamet er("grpTyp eID"));
} else {
grpTypeID = null;
}
if(grpTypeID.equals(grpTyp eDTO.getGr oup_TypeID ())){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
if it is int and NOT Integer then you should have
int grpTypeID; // Default to 0
if(request.getParameter("g rpTypeID") != null){
grpTypeID = new Integer(request.getParamet er("grpTyp eID").intV alue());
} else {
grpTypeID = 0;
}
if(grpTypeID == grpTypeDTO.getGroup_TypeID ()){
grpTypeName = grpTypeDTO.getGrpTypeName( );
}
Regards
Dave
What does it return of grpTypeDTO.getGroup_TypeID
if it is Integer, then you can return TRUE if you have
Integer grpTypeID = null;
if(request.getParameter("g
grpTypeID = new Integer(request.getParamet
} else {
grpTypeID = null;
}
if(grpTypeID.equals(grpTyp
grpTypeName = grpTypeDTO.getGrpTypeName(
}
if it is int and NOT Integer then you should have
int grpTypeID; // Default to 0
if(request.getParameter("g
grpTypeID = new Integer(request.getParamet
} else {
grpTypeID = 0;
}
if(grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeName = grpTypeDTO.getGrpTypeName(
}
Regards
Dave
ASKER
What does it return of grpTypeDTO.getGroup_TypeID ()? Is it Integer or int?
Integer
Integer
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use this printout statement instead (wrong cut/paste :-) :
System.out.println("Compar ed values: " + grpTypeDTO.getGroup_TypeID () + " -> " + grpTypeID);
System.out.println("Compar
ASKER
Dave,
I tried the last suggestion you made (10:20PM) and here is the error:
22:21:34,243 ERROR [Engine] ApplicationDispatcher[/sec urityAdmin ] Servlet.servic
e() for servlet jsp threw exception
java.lang.NullPointerExcep tion
at org.apache.jsp.Administrat ion.groupT ypesMgmt_j sp._jspSer vice(group Typ
esMgmt_jsp.java:224)
This is line 224
if(grpTypeID.equals(grpTyp eDTO.getGr oup_TypeID ())){
RCMB
I tried the last suggestion you made (10:20PM) and here is the error:
22:21:34,243 ERROR [Engine] ApplicationDispatcher[/sec
e() for servlet jsp threw exception
java.lang.NullPointerExcep
at org.apache.jsp.Administrat
esMgmt_jsp.java:224)
This is line 224
if(grpTypeID.equals(grpTyp
RCMB
Mmm....
Then it means that your grpTypeID is null. Subsequently, it means that request.getParameter("grpT ypeID") is also null. Is request.getParameter("grpT ypeID") returning some values? (I don't think so)
Regards
Dave
Then it means that your grpTypeID is null. Subsequently, it means that request.getParameter("grpT
Regards
Dave
ASKER
Yee --- Hah
That fixed it. Thanks so very much.
RCMB
That fixed it. Thanks so very much.
RCMB
If you want you can apply the change I suggested at (10:23PM) to avoid the NullPointer exception.
But the fact that it is null explain why the compare will fail :-)
request.getParameter("grpT ypeID") is case sensetive.
Make sure the sent html contains the right parameter name
But the fact that it is null explain why the compare will fail :-)
request.getParameter("grpT
Make sure the sent html contains the right parameter name
rcmb,
I think suprapto45 should also get points. don't you think so?
I think suprapto45 should also get points. don't you think so?
aozarov,
thanks for your attention :).
Regards
Dave
thanks for your attention :).
Regards
Dave
ASKER
Okay -- I agree with you because he did a great deal of work. How can I do it now that I have awarded you points?
RCMB
RCMB
NP :-)
rcmb,
You can use this link https://www.experts-exchange.com/Community_Support/
to ask to re-open the question so you can give suprapto45 to points he deserves.
rcmb,
You can use this link https://www.experts-exchange.com/Community_Support/
to ask to re-open the question so you can give suprapto45 to points he deserves.
ASKER
Done -- Once complete I will reassign the points -- Thanks for your help and taking the time to look out for other experts.
RCMB
RCMB
:-)
Thanks RCMB and aozarov
I appreciate it :)
Regards
Dave
I appreciate it :)
Regards
Dave
You can use equals method.
if(grpTypeID == grpTypeDTO.getGroup_TypeID
grpTypeName = grpTypeDTO.getGrpTypeName(
}
regards
Dave