File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Not letting me create and add user defined object to ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Not letting me create and add user defined object to ArrayList" Watch "Not letting me create and add user defined object to ArrayList" New topic
Author

Not letting me create and add user defined object to ArrayList

Tom Mordon
Ranch Hand

Joined: Apr 26, 2012
Posts: 30
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
Bartender

Joined: Oct 14, 2005
Posts: 18649
    
    8

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

Joined: Apr 26, 2012
Posts: 30
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
Bartender

Joined: Oct 14, 2005
Posts: 18649
    
    8

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

Joined: Apr 26, 2012
Posts: 30
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
Bartender

Joined: Oct 14, 2005
Posts: 18649
    
    8

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

Joined: Apr 26, 2012
Posts: 30
Thank you, that makes sense now. Need to pay attention to imports.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not letting me create and add user defined object to ArrayList