Club PA 2.0 has arrived! If you'd like to access some extra PA content and help support the forums, check it out at patreon.com/ClubPA
The image size limit has been raised to 1mb! Anything larger than that should be linked to. This is a HARD limit, please do not abuse it.
Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

Java import problems

john fechonjohn fechon Registered User regular
edited November 2006 in Help / Advice Forum
I was hired by a researcher at my college and my current task is to debug a java program that someone else wrote last semester. I'm not very familiar with java, but I managed and have fixed almost every problem. The remaining problem is the date. I want to be able to set a user specified date. I looked at the online documentation for java date, and it lists some constructors and other methods which do exactly what I need. But for some reason, those constructors can't be found. It can find the basic date() constructors. The same goes for other functions I've tried to use.

My question is this: I'm using Eclipse, is there a way to update or import the neccessary libraries/packages?

john fechon on

Posts

  • Bob SappBob Sapp Registered User regular
    edited November 2006
    Two things:

    1) make sure you're using java.util.Date, not java.sql.Date

    2) all the constructors for Date (except Date()) are deprecated, and eclipse doesn't like that. Use the GregorianCalendar class

    Bob Sapp on
    fizzatar.jpg
  • john fechonjohn fechon Registered User regular
    edited November 2006
    I'm using java.util.Date. It couldn't find java.sql.

    GregorianCalendar is another one of those classes/methods it can't find.

    john fechon on
  • Bob SappBob Sapp Registered User regular
    edited November 2006
    What JDK version do you have installed?

    What is the error eclipse gives you? Do you get the error when you use the methods/classes, or when you do the import statement?

    Bob Sapp on
    fizzatar.jpg
  • john fechonjohn fechon Registered User regular
    edited November 2006
    I'm still not very good with java, so I'm not sure where to find that. The java version on the computer is 1.5.0, and I'm using eclipse 3.0.

    If I try using the date constructor, it says that its undefined.
    If I try using GregorianCalendar, it says that it 'cannot be resolved or is not a type'.

    I noticed a new version of eclipse is out (3.2.1), but this version should still have the date/calendar stuff.

    john fechon on
  • Bob SappBob Sapp Registered User regular
    edited November 2006
    A few things:

    1) Java comes in two flavors, the JDK and the JRE. The JDK (Java Development Kit) is what Eclipse should be using to compile, etc. The JRE is what non-developers use, it allows you to run java programs. You want to make sure you have JDK 1.5.0 or higher installed on your system, and that Eclipse is using it. You'd probably find it installed in C:\Program Files\Java. You'll see folders called jdk1.5.0_07 or jre1.5.0_07 so it should be simple to see which JDK you have installed, if you can find its folder.

    2) Did you import the classes (import java.util.GregorianCalendar;)? Or fully qualifiy them, like: java.util.GregorianCalendar = new java.util.GregorianCalendar?

    3) You might want to give NetBeans a try. I like it much better than Eclipse for Java, personally. Might make your problems go away. http://www.netbeans.org/

    Other than that, I'm out of ideas as I'm no eclipse expert.

    Bob Sapp on
    fizzatar.jpg
  • john fechonjohn fechon Registered User regular
    edited November 2006
    The java folder contains 4 folders ranging from j2re1.4.2_03 to jre1.5.0_06.

    Importing and fully qualifying produce the same errors.

    I think the person who originally wrote this may have done something wrong. Looking at the code alone makes me think this person wasn't the best person to be coding (instead of else statements, they threw exceptions instead).

    I'm gonna install netbeans on this machine and see if i can transfer between the two. My main concern is that I won't be able to reconfigure the many files and directories this beast uses. Thanks for the help Bob, unless anyone has a better solution this thread is done.

    john fechon on
  • shadowaneshadowane Registered User regular
    edited November 2006
    Date works fine, but there isn't a constructor for it. It has a static constructor.
    private static final DateFormat dateFormatter = 
        new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
    
    dateFormatter.format(new Date(System.currentTimeMillis())
    
    That works and returns a string in the form of the formatter. You don't need that, just thought I'd show you.

    Also, are you looking at the 1.5 javadocs?

    shadowane on
    Rich on Beer - I talk about drinking beer. You read about it.
  • TheCapnTheCapn Registered User regular
    edited November 2006
    If you've never used the class before, you need to have an import statement(as mentioned above). I use IBM's RAD at work, which is based on eclipse. Trying hitting Ctrl + shift + o . Assuming the shortcuts are the same, that will add(and also remove) any import statement you do/don't need anymore. You can also try highlighting the class name and hitting ctrl + shift + m, which does the same thing, but only for the class you've highlighted.

    TheCapn on
    Tacopants - a tasty comfortable combination.
This discussion has been closed.