Results 1 to 9 of 9
- 03-27-2011, 04:07 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 46
- Rep Power
- 0
How to fix this "incompatible types" issue
In the code below if I don't use a cast:
I get:Java Code:ArrayList<Instance> currentEvent = mapItem.getValue();
Java Code:incompatible types found : java.lang.Object required: java.util.ArrayList<Instance> ArrayList<Instance> currentEvent = mapItem.getValue();
If I use a cast:
I getJava Code:ArrayList<Instance> currentEvent = (ArrayList<Instance>) mapItem.getValue();
mapItem is aMap.Entry. What am I doing wrong ?Java Code:warning: [unchecked] unchecked cast found : java.lang.Object required: java.util.ArrayList<Instance> ArrayList<Instance> currentEvent = (ArrayList<Instance>) mapItem.getValue();
thanks
-
you may add items to an arraylist like this:
currentEvent.add(Object)
but the object should match the ArrayList type in this case: Instance
but the point is currentEvent = Object is wrong syntax.
-
- 03-27-2011, 04:20 PM #4
Member
- Join Date
- Aug 2008
- Posts
- 46
- Rep Power
- 0
@ozzyman But i don't need to add an item to an ArrayList, I'm getting an ArrayList and that's it.
@Fubarable These are the initializations
thanksJava Code:instancesLists = new HashMap<String, ArrayList<Instance>>(); ... Iterator it = instancesLists.entrySet().iterator(); while (it.hasNext()) { Map.Entry mapItem = (Map.Entry)it.next();
- 03-27-2011, 04:44 PM #5
Member
- Join Date
- Aug 2008
- Posts
- 46
- Rep Power
- 0
Any help ? I'm a bit stuck
I'm currentEvent is a List i'm retrieving from the mapItem, I'm not adding items to currentEvent.
mapItem contains Lists
- 03-27-2011, 04:49 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-27-2011, 05:22 PM #7
Member
- Join Date
- Aug 2008
- Posts
- 46
- Rep Power
- 0
I've changed as you suggest, the iterator declaration
but I still get the same errorJava Code:Iterator<Map.Entry<String, ArrayList<Instance>>> it = instancesLists.entrySet().iterator();
This is my code: #1722600 - PastieJava Code:incompatible types found : java.lang.Object required: java.util.ArrayList<Instance> ArrayList<Instance> currentEvent = mapItem.getValue();
- 03-27-2011, 05:34 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 03-27-2011, 05:37 PM #9
Member
- Join Date
- Aug 2008
- Posts
- 46
- Rep Power
- 0
Similar Threads
-
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 04:21 PM -
incompatible types...What is "Dispatch" ?
By ollyworks in forum Java AppletsReplies: 1Last Post: 09-10-2009, 03:03 AM -
Facing issue in printing user like "ab\\cd"
By psmhelp in forum New To JavaReplies: 4Last Post: 04-27-2009, 01:28 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks