• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable type question?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
If strSubmittedDate is Date type so is it the way that I can define it?
Date strSubmittedDate=" ";
Am I right? and Date will call "Variable type?"
Thanks,
Elahe
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi elahe,
For initialization of an object you have three choices:
1. Assign it to another of the same type
Date submittedDate = anotherDate;
2. Assign it to null
Date submittedDate = null;
3. Assign it using the new operator.
Date submittedDate = new Date();
Regards,
Manfred.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Manfred got it
and also are these two lines correct?
Date today=new Date();
dSubmittedDate = today;
thanks,
Elahe
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and as you said so this variable type for dSubmittedDate is correct right?
try
{
int nBugNumber=0;
Date dSubmittedDate=null;
int userID=0;
String strContact=" ";
....
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what you have done with this code is to create a variable of type Date with the name dSubmittedDate, but the variable is not referencing ANY object at this time.
[ April 17, 2002: Message edited by: Cindy Glass ]
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I defined dSubmittedDate and all related field in Date type but why I am getting this error?
Thanks,
Elahe
No method found matching setSubmittedDate(Date)
oBug.setSubmittedDate( dSubmittedDate );
^
1 errors
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because dSubmittedDate is null. It is not pointing a a Date object yet.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But base on my code I put current date on it please have a look to my code:
Thanks,
Elahe
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled it but still I am getting this error?
Highly appriciate for any advice.
Elahe
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where in Bug is the code for the method
setSubmittedDate( Date d );
Can you show us that code?
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cindy I didn't get exactly your question since I don't have such a code in my program. I hope I can answer this way...
Here is my whole code:
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a line of code:
Bug oBug = new Bug();
which means that you are constructing a variable of type "Bug" named oBug.
There is no class in the Sun API named Bug. Therefore YOU or your friends must have the code for that class. The compiler is saying that the code for the Bug class does not have the method that you requested.
Since WE can't look at the code for Bug - YOU will have to look.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the clarification. Yes I have a class with the name of Bug and the reason it is not in my program and I just call it because I used MVC method to refactor my code...
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I found my answer just I need to put "java.sql.Date " in front of SubmittedDate=null
in my code.
...
int nId =0;
int nBugNumber=0;
java.sql.Date dSubmittedDate=null;
String strFixedDate=" ";
int userID=0;
String strDesc=" ";
...
Thanks,
Elahe
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elahe:
just a suggestion: Since working on problems with you in various forums, I noticed that you use Date objects a lot but never specify which Date object you really want. What I mean is that if you have "import java.util.*;" and "import java.sql.*;" then you create a date objectwhich Date??? a java.util.Date or a java.sql.Date? I know from experience that a java.sql.Date does not have an empty constructor, but I still had to look at the docs to make sure! You will avoid confusion for the person that has to maintain your code(and for yourself!) by using the fully qualified name:
cheers, Jamie
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very good notice thank you so much for your attention, So Jamie I have to choose one of them right? java.util.Date Or java.util.Date
Elahe
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry I mean or java.sql.Date
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic