Casting vector from object
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
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...
You're trying to call valueOf() as if its part of your own class. It's a static method belonging to the String class.
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:
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.
Last Post: 03-27-2002, 11:05 PM
By Derek Mooney in forum .NET
Last Post: 10-29-2001, 09:44 PM
By Jaco de Villiers in forum XML
Last Post: 06-01-2001, 06:50 PM
Last Post: 05-10-2001, 04:22 AM
By Tom Shreve in forum Enterprise
Last Post: 04-07-2000, 09:15 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL