Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Calendar help - who is wrong, me or Netbeans?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Calendar help - who is wrong, me or Netbeans?

    I want to set a couple of dates on Calendars and do a couple of very simple things with them, but I can't even seem to set a date.
    I have this:

    "package pointscalculator;
    import java.util.*;

    public class Week {
    Calendar startDate = Calendar.getInstance();
    startDate.set(2012,6,21,0,0);
    ...[other code]......"

    Netbeans reckons that this is illegal, but in both the books I have this should work.
    The Netbeans error:
    "package startDate does not exist
    <identifier> expected
    illegal start of type"

    I can't work out what I've done wrong. Or has my Netbeans spazzed out in some crappy way?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Calendar help - who is wrong, me or Netbeans?

    Take netbeans out of the picture- compile via the command prompt. Do you still get the error? If so, it's your fault. If not, it's netbeans's fault.

    If it is indeed your fault (and I expect it is), you should put together an SSCCE that demonstrates the problem.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Calendar help - who is wrong, me or Netbeans?

    I also moved this thread, as it doesn't directly deal with Collections or generics.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Calendar help - who is wrong, me or Netbeans?

    Why are you calling methods (startDate.set(2012,6,21,0,0);) outside of a constructor or method? That is probably what it is complaining about.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Calendar.MONTH return wrong value
    By bczm8703 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 5th, 2011, 09:33 AM
  2. getTimeInMillis() from the Calendar class returns wrong values
    By 16mydream in forum Java Theory & Questions
    Replies: 2
    Last Post: February 16th, 2011, 01:29 PM
  3. Calendar help
    By moonieass13 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 31st, 2009, 12:43 AM
  4. calendar
    By subhvi in forum AWT / Java Swing
    Replies: 2
    Last Post: September 29th, 2009, 11:02 PM
  5. which calendar to use?
    By rptech in forum AWT / Java Swing
    Replies: 6
    Last Post: August 30th, 2009, 03:18 PM

Tags for this Thread