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 11:28 AM.
Brilliant, thanks guys, seems to have done the trick!
By alirazvi in forum Java
Last Post: 08-18-2005, 11:43 AM
By swapnil_paranja in forum C++
Last Post: 08-08-2005, 08:15 AM
Last Post: 04-06-2005, 05:30 PM
By Patrick Ireland in forum .NET
Last Post: 08-02-2001, 05:22 PM
By Marion Elledge in forum XML
Last Post: 04-17-2001, 03:20 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center