Hi i quite new to java and am currently having a problem with Hashmaps,
I have stored an object called Users in a Hashmap called clients, i am then trying to return the object based on the its ID and pass it into a temp Users object so i might use the methods.
The current error message is incompatable types..
Here is some of my code...
Map Clients = new HashMap();
Clients.put(UserName, new Users(UserName, Password, IP, PortNo));
Users User3 = new Users();
Is there a simple soultion to this?
Thanks in Advance.
If you are getting a compile-time error, just insert a cast to cast Client.get(UserName) to be of type user. e.g.
Hope this helps.
User3 = (Users) Client.get(UserName);
Clients.put(UserName, new Users(UserName, Password, IP, PortNo)); // ok
Users User3 = new Users(); // no need for this statement
Users User3=(Users)Clients.get(UserName); // you must typecast, get returns Object
Last edited by sjalle; 12-10-2005 at 12:28 PM.
Brilliant, thanks guys, seems to have done the trick!
By alirazvi in forum Java
Last Post: 08-18-2005, 12:43 PM
By swapnil_paranja in forum C++
Last Post: 08-08-2005, 09:15 AM
Last Post: 04-06-2005, 06:30 PM
By Patrick Ireland in forum .NET
Last Post: 08-02-2001, 06:22 PM
By Marion Elledge in forum XML
Last Post: 04-17-2001, 04:20 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