-
Hash Maps
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();
User3=Clients.get(UserName);*Error
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.
Code:
User3 = (Users) Client.get(UserName);
Hope this helps.
~evlich
-
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 11:28 AM.
eschew obfuscation
-
Brilliant, thanks guys, seems to have done the trick!
Similar Threads
-
By alirazvi in forum Java
Replies: 0
Last Post: 08-18-2005, 11:43 AM
-
By swapnil_paranja in forum C++
Replies: 1
Last Post: 08-08-2005, 08:15 AM
-
Replies: 10
Last Post: 04-06-2005, 05:30 PM
-
By Patrick Ireland in forum .NET
Replies: 0
Last Post: 08-02-2001, 05:22 PM
-
By Marion Elledge in forum XML
Replies: 0
Last Post: 04-17-2001, 03:20 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
|
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
|
Bookmarks