Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to handle date 1

Status
Not open for further replies.

112055

Programmer
May 13, 2002
61
US
Hello,
I know it's wrong to check for !=null, but can anyone tell me the correct to handle this error.
The method getDaysToExpiration() returns an int

here I have ...
String tempDate = "";
if(aUser.getDaysToExpiration() !=null) tempDate = aUser.getDaysToExpiration().trim();



Generated servlet error:
D:\Tomcat\work\Standalone\localhost\WI\maintainUser$jsp.java:257: Incompatible type for int. Can't convert int to null.
if(aUser.getDaysToExpiration() !=null) tempDate = aUser.getDaysToExpiration().trim();


many thanks
 
Well since getDaysToExpiration() is not a Java API we have no documentation that explains the meaning of the return value. How can we tell you what to check for?

Possibly you want to check for ZERO?
Code:
if( aUser.getDaysToExpiration() != 0)

however if that function returns an (int) type then
aUser.getDaysToExpire().trim() is not going to work since you can't "trim" an integer.

You post is very confusing.

-pete
 
Sorry,
let me try again..
I have ....
if(aUser.getDaysToExpiration() !=null) tempDate = aUser.getDaysToExpiration().trim();

I know I can't do null and I can't do trim..

so I set it up like the following ...

int tempDate = 0;
tempDate = Integer.parseInt(aUser.getDaysToExpiration("tempDate"));


I got the following error message ..
Generated servlet error: D:\Tomcat\work\Standalone\localhost\WI\maintainUser$jsp.java:275: Incompatible type for method. Can't convert int to java.lang.String. tempDate = Integer.parseInt(aUser.getDaysToExpiration());

**********************************************
this method getDaysToExpiration returns an int
see below....

public int getDaysToExpiration()
{
return m_daysToPasswordExpire;
}


I am not looking at something right, can anyone tell me where I screwed up?

Thanks,
Ngai
 
>> int tempDate = 0;
>> tempDate = Integer.parseInt(aUser.getDaysToExpiration("tempDate"));

Well that is rather confusing. I think you want this:

Code:
int tempDate = aUser.getDaysToExpiration();

-pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top