-
Casting vector from object
Hi all,
I have a vector which has a string of dates retrieved from a DB
what I need to do is parse the string which is in a vector and return it in a Date object type
i.e.
parseDate(vec.get(i));
private void parseDate(Object o)
{
Date isoDate = valueOf(o);
}
However, this returns the error "the method valueOf(Object) is undefined for the type <Classname>
Can anyone please tell me why I get this error and how I could go about fixing it...
Many Thanks
-
You're trying to call valueOf() as if its part of your own class. It's a static method belonging to the String class.
String.valueOf();
-
If you know that the objects you are storing in the vector are Strings, why would you use the "Object" class as the classtype of your argument to your method instead of a String object?. The compiler won't know that you want to use the String class methods or to treat the object as anything other than an Object.
If you are using Java 5, make your vector a vector of Strings
Vector<String> myVector = new Vector<String>();
then. when you get() from the vector, it returns a String to you.
If you are using an earlier verson, you'll need to cast the type of the object returned by the get(i) to a String object:
parseDate((String)vec.get(i));
I suggest that you use the DateFormat class to parse the String to create a date object. Look at the parse( String s ) method, which returns a Date.
Similar Threads
-
Replies: 1
Last Post: 03-27-2002, 11:05 PM
-
By Derek Mooney in forum .NET
Replies: 94
Last Post: 10-29-2001, 09:44 PM
-
By Jaco de Villiers in forum XML
Replies: 1
Last Post: 06-01-2001, 05:50 PM
-
Replies: 4
Last Post: 05-10-2001, 03:22 AM
-
By Tom Shreve in forum Enterprise
Replies: 0
Last Post: 04-07-2000, 08:15 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|