• Post Reply Bookmark Topic Watch Topic
  • New Topic

Whats wrong with tis line (Calender related)  RSS feed

 
Robert Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar todaysDate1 = new GregorianCalendar(todaysDateYearTemp + ", Calendar." + todaysDateMonth + ", " + todaysDateDayTemp);

this is the error that it gives:
"ViewLeagueTourOwnerServlet.java": Error #: 300 : constructor GregorianCalendar(java.lang.String) not found in class java.util.GregorianCalendar at line 50, column 32

the value of todaysDateYearTemp is 2005
the value of todaysDateDayTemp is 14
the value of todaysDateMonthTemp is February

the line is therefore changed to:
Calendar todaysDate1 = new GregorianCalendar(2005, Calendar.February, 14);

i dont understand what the error is or how to fix it
 
Rawat (Zeon)
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,


The problem with the following line of code is that it is concating the tdaysDateYearTemp and "Calendar." + todayDateMonth + ", " + todaysDateDayTemp.


Calendar todaysDate1 = new GregorianCalendar(todaysDateYearTemp + ", Calendar." + todaysDateMonth + ", " + todaysDateDayTemp);


Change it to :

Calendar todaysDate1 = new GregorianCalendar(todaysDateYearTemp ,("Calendar." + todaysDateMonth),todaysDateDayTemp);


-Zeon
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, since the commas are in strings, the final line becomesJava doesn't support executing strings as code, so you cannot programmatically build "Calendar.Februrary" to access the constant Calendar.FEBRUARY.

You have two choices: 1) build a mapping from month string to month integer and 2) build the whole string as you've done and parse it using SimpleDateFormat.You'll need to add error handling for the case where the format doesn't match the build String. And of course you should choose more meaningful variable names than I did.
 
Robert Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nope... i tried that just there now and it didnt work.

im even trying to used the Date object but when i try to create that it says "Reference to Date is ambiguous; both class java.sql.Date in package java.sql and class java.util.Date in package java.util match"

i need those two packages for other things so i cant delete one.
this was my Date object:
Date d1 = df.parse("2005-02-11");


i duno what to do.
 
Robert Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do u mean for your first suggestion david.
do u mean instead of using "todaysDateMonth" for february, just store "02" for february in an integer?

i cant use the Date object seeing as its 'ambiguous', or is there a way around that?

thanks for your replies
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If two packages that you import have classes with the same name, use the fully-qualified class name in your code -- it will bypass the import for that class.For my first suggestion, you'd need a mappnig function to convert the String month names to their equivalent integer numbers:I'd go the other route if you can though. Let Java do all the parsing and mapping for you. Java's code also works in different languages.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, you can also import individual classes if you don't need both Dates. For example, if all you need from java.sql is Connection, Statement, ResultSet, and SQLException, import only those (one per line).
 
Robert Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks.

i looked up stuff and i think i can use GregorianCalendar(int, int, int);
ie, use an integer value for the month.

for the normal calender and the gregorianCalender isnt the integer values for months one behind? what i mean is january is 0, february is 1, march is 3 etc.

isnt that true for the both cases?

i will try both ways and see how i get on.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, sorry. I never need the numeric values like that so I forget that months are zero-based and day-of-months are one-based. Gotta love consistency!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!