Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not letting me create and add user defined object to ArrayList

 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been hacking away at me check list that allows me to add strings via dialog box. The strings are then added to an ArrayList<Item> which I have a separate class that defines that object. As far as I can tell I have the syntax correct but it tells me "The constructor ClickData.Item(String, boolean) is undefined"
The problem is in the addItem() method "aiItems.add(new Item(sItem, true));" Any thoughts as to how I can get this to work so that I can add it to the ArrayList<Item>? Thanks in advance.

ListActivetyDemo.java


Item.java
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the message mention "ClickData.Item" or "ClipData.Item"? You imported the latter, so perhaps you retyped the error message with errors instead of just copying and pasting it?

In any case the Item class whose code you posted isn't either of those. If you want to use the Item class that you posted, then you shouldn't be importing a different Item class (i.e. android.content.ClipData.Item). In fact since the Item class that you posted is in the same package as your ListActivityDemo class, you shouldn't have to import any Item class at all.
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says ClipData.Item(String, boolean), pasted below is the error I copied. Yeah its weird will try retyping the method to see if that does anything.

"The constructor ClipData.Item(String, boolean) is undefined"
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this "Item" class you want to use... is it the Item class whose code you posted, or is it that ClipData.Item class?
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is I have no idea what ClipData.Item is, I'm just trying to use Item.java since it defines the Item object I created. So yes I'm trying to use the Item.java which defines my Item object.
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Mordon wrote:The thing is I have no idea what ClipData.Item is, I'm just trying to use Item.java since it defines the Item object I created. So yes I'm trying to use the Item.java which defines my Item object.


Then importing ClipData.Item wasn't the right thing to do. I expect you did that at an earlier stage when your IDE told you it couldn't find an Item class and gave you a list of things which might be suitable, and you chose one at random from the list. Or something like that. Anyway you don't want to use ClipData.Item so don't import it.
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, that makes sense now. Need to pay attention to imports.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic